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
LVL 2
laes_Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MikeOM_DBACommented:

Use two single quotes:

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

0
Artysystem administratorCommented:
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}"
0
laes_Author Commented:
i have resolved the problem
i put the awk command into file with this quote
and i called awk -f awkscript file
0
MikeOM_DBACommented:

Using two single quotes inside the pair of single quotes that delimit the awk statement also works.
0
GranModCommented:
PAQed with points refunded (50)

GranMod
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.