Issue
I have two files. I am doing some action on file1
which generates the another file file2
Here is my file1 content:
class parent {
public void bye() {statement}
public void home1() {statement}
public void Work() {statement}
public void apple() {statement}
public void fruits() {statement}
}
Here is my produced file2 content:
parent
{
void parent.<init>() (dex_method_idx=8) {statement}
void parent.Work() (dex_method_idx=13) {statement}
void parent.apple() (dex_method_idx=9) {statement}
void parent.bye() (dex_method_idx=10) {statement}
void parent.fruits() (dex_method_idx=11) {statement}
void parent.home1() (dex_method_idx=12) {statement}
}
The generated file2 having fixed pattern. The first function code will always be init paragraph. Then it will print the function code which starts from Capital letter (ex. Work). Then print the remaining function code by alphabetical order.
How could I print the function code of file2
according to the order of file1
function code.
Expected output:
parent
{
void parent.<init>() (dex_method_idx=8) {statement}
void parent.bye() (dex_method_idx=10) {statement}
void parent.home1() (dex_method_idx=12) {statement}
void parent.Work() (dex_method_idx=13) {statement}
void parent.apple() (dex_method_idx=9) {statement}
void parent.fruits() (dex_method_idx=11) {statement}
}
Please suggest me an approach.
Solution
When I execute above code, it only display content of file1
It is not displaying above output
This may be due to having a pre-POSIX awk
that doesn't know character classes ([:alnum:]
, [:space:]
). Here's a version of Ed Morton's script without character classes:
BEGIN { FS="[ .]+" }
NR==FNR {
if (/^ *} *$/) inDefs=0
if (inDefs) map[$4] = $0
if (/^ *{ *$/) inDefs=1
next
}
FNR==1 {
print $2 ORS "{"
print map["<init>()"]
next
}
{ print $4 in map ? map[$4] : $0 }
Answered By - Armali