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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing reservede carakters - ex using awk '{gsub("|","",$

Status
Not open for further replies.

Larshg

Programmer
Joined
Mar 1, 2001
Messages
187
Location
DK
Hi

I trying to replace " and |

I've usede something like this
print '|' |awk '{gsub("|","-",$0); print }'

But this does not work - I can't use | in gsub

/Larshg
 
Prefix with a backslash...

print '|' |awk '{gsub("\|","-",$0); print }'
 
What if it is '

this version won't work - becouse awk think that ' endes the awk sentence
echo ---|awk '{gsub("---","\'",$0); print }'

Larshg
 
Try this:
echo ---|awk "{gsub(/---/,\"'\",$0); print }"

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Can't get it to work

> echo --- |awk "{gsub(/---/,\"'\",$0); print }"
-
>


Larshg
 
You can use the octal number of the ascii char ...

echo ---|awk '{gsub("---","\047",$0); print }'
 
You can also define an awk variable :
[tt]
echo ---| awk '{gsub(/---/,Q);print}' Q="'"
[/tt]

Jean Pierre.
 
Try this:
echo X---|awk "{gsub(/---/,\"'\",$0); print }"
I guess it's a echo problem

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top