Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

escaping '

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
US
$ awk '{print "'"}'
>
-bash2-2.05b$ awk '{print "\'"}'
>
-bash2-2.05b$ awk '{print ".'"}'
>
-bash2-2.05b$ awk '{print ".\'"}'
>

How am I escaping the ' character? I need to print a statement that contains the following:

awk '/403/ && /Request/{print "perl -pi -e 's/logged/"$3" logged/g'"}'

where the output is:
perl -pi -e 's/logged/$3 logged/g'

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
'\'' scrap that one sorry for the wasted time

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
Hi

Could you please post your code between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] tags ? The difference between one double quote ( " ) and two single quotes ( ' ) is more evident.

Escaping is not [tt]awk[/tt] problem, is shell related. In [tt]bash[/tt] and [tt]ksh[/tt] you can not escape the single quote in a single quote delimited string.
Code:
[gray]# use duoble quotes around the string, but then you must escape other language elements too, like field references[/gray]

awk "{print \"'\"}"

[gray]# interrupt the single quotes, but this messes up the code considerably[/gray]

awk '{print "'"'"'"}'

[gray]# use variable, but then you have to add the parameter at call[/gray]

awk -vq="'" '{print q}'
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top