Link to home
Start Free TrialLog in
Avatar of laes_
laes_

asked on

quote problem in awk

i get unmatch problem in awk

cat file| awk ' { if($0 ~/^val=track/) { print "/bin/awk '{ print $4 ; exit 0 }'" } else { print $2 } }'

the problem is due to the awk quote in the if block ("/bin/awk '=> this quote cause the crash)

even if i place a back slash before (i.e /bin/awk \') it stays the same problem

so could u help me
thanks
Avatar of MikeOM_DBA
MikeOM_DBA
Flag of United States of America image


Use two single quotes:

cat file| awk ' { if($0 ~/^val=track/) { print "/bin/awk ''{ print $4 ; exit 0 }''" } else { print $2 } }'

Avatar of Arty K
man sh
 Backslash has no special meaning inside  a  pair  of  single quotes.
...
but a single quote  can  not  be quoted inside a pair of single quotes.
..

Will this command work as you like?
awk '/^val=track/{print $4; next};{print $2}' file

it's not you have asked for
that is closer for your question:
awk "/^val=track/{  print \"/bin/awk '{print \$4; exit 0}'\"; next};{print \$2}"
Also if you want to get real $4 instead of just literal:
awk "/^val=track/{  print \"/bin/awk '{print \" $4 \"; exit 0}'\"; next};{print \$2}"
Avatar of laes_
laes_

ASKER

i have resolved the problem
i put the awk command into file with this quote
and i called awk -f awkscript file

Using two single quotes inside the pair of single quotes that delimit the awk statement also works.
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial