user2713375
user2713375

Reputation: 63

AWK command to separate line using Field-sperator

 Info 750: local macro 'ADD_GEN_METHOD' (line 149, file /home/vya3kor/vmshare/vya3kor_rbin_g3g_tas_lcmccatestadapter.vws/di_cfc/components/spm/LcmProject/framework/cca/server/generic/spm_CcaServiceHandlerFiParamConfig.cpp) not referenced

I want to separate above line using awk with field-separator (line

I used this command but it's not working

$ grep Info.* 1.txt |awk -F "(line" '{print $1}'
error : awk: fatal: Unmatched ( or \(: /(line/

output I want:

/di_cfc/components/spm/LcmProject/framework/cca/server/generic/spm_CcaServiceHandlerFiParamConfig.cpp%149%Info 750%local macro 'ADD_GEN_METHOD'%

So I used this command :

$ grep  '^[Ii]nfo.*:'|
awk -F ":" '{print $1"%" $2}'| 
awk -F ", file.*.vws" '{print $1"%" $2 }'| 
awk -F ") not referenced" '{print $1"%" }'|
awk -F '(' '{print $1"%" $2"%" $3}'|
awk -F "line" '{print $1 $2 $3 }' | 
awk -F "%" '{print $1$ "\n2" $3 $4 $4 $5}'

Upvotes: 1

Views: 113

Answers (5)

Ed Morton
Ed Morton

Reputation: 203522

$ cat file
Info 750: local macro 'ADD_GEN_METHOD' (line 149, file /home/vya3kor/vmshare/vya3kor_rbin_g3g_tas_lcmccatestadapter.vws/di_cfc/components/spm/LcmProject/framework/cca/server/generic/spm_CcaServiceHandlerFiParamConfig.cpp) not referenced
$
$ cat tst.awk
BEGIN{ FS=" *[()] *"; OFS="%" }
/^[Ii]nfo.*:/ {
    split($2,a,/[ ,]+/)
    sub(/: /,OFS,$1)
    sub(/.*\.vws/,"",$2)
    print $2, a[2], $1 OFS
}
$
$ awk -f tst.awk file
/di_cfc/components/spm/LcmProject/framework/cca/server/generic/spm_CcaServiceHandlerFiParamConfig.cpp%149%Info 750%local macro 'ADD_GEN_METHOD'%
$

or you could do it all in GNU awk with one gensub() call or just use sed as @chthonicdaemon suggested since this is just a simple substitution on a single line.

Upvotes: 0

chthonicdaemon
chthonicdaemon

Reputation: 19770

With all that chopping, you may be better off with sed:

sed -n '/^[Ii]nfo/s/\(Info.*\): \([^(]*\).*file \([^)]*)\) .*/\3%\1%\2/gp' 1.txt

Upvotes: 0

Kent
Kent

Reputation: 195059

instead of escaping the (, you can do in this way:

awk -F'[(]line' '... your codes'

personally I think it is easier to read.

Upvotes: 2

Avinash Raj
Avinash Raj

Reputation: 174706

You need to use three backslashes if the Field Seperator was set through -v,

$ echo 'Info 750: local macro 'ADD_GEN_METHOD' (line 149, file /home/vya3kor/vmshare/vya3kor_rbin_g3g_tas_lcmccatestadapter.vws/di_cfc/components/spm/LcmProject/framework/cca/server/generic/spm_CcaServiceHandlerFiParamConfig.cpp) not referenced' | awk -v FS="\\\(line" '{print $1}'
Info 750: local macro ADD_GEN_METHOD 

Upvotes: 0

anubhava
anubhava

Reputation: 785156

You can use this awk:

awk -F '\\(line' '{print $1}'
Info 750: local macro ADD_GEN_METHOD

( is special regex symbol that needs to be escaped.

Upvotes: 3

Related Questions