The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to pass option with "at" command? bd9439 UNIX for Dummies Questions & Answers 3 03-24-2008 12:45 PM
Running command "md5" on remote host not working. ynilesh UNIX for Advanced & Expert Users 1 02-01-2008 04:15 AM
Listing only directories in the current working directory using the "ls" command igandu UNIX for Dummies Questions & Answers 2 05-12-2006 01:47 AM
Unix "at" / "Cron" Command New Problem...Need help Mohanraj UNIX for Dummies Questions & Answers 3 01-26-2006 04:08 PM
Does "gzip" have a no prompt option on it for overwriting if file exists? LordJezo UNIX for Dummies Questions & Answers 1 07-29-2004 06:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Jun 2008
Posts: 1
Thumbs up sub option of awk command not working with "\" character.

Hi all,

I would like to replace some string in a text file by some string which would contains special characters like "/","\".
I.e. I have a text file with the statement contactperson somewhere in it.
Now I want to replace it by something else which includes special
characters like "/","\"

For this I'm using awk command like shown below:
cat hh | awk -v con="/BGL04/" '{gsub(/contactperson/,con)}1' > final

The above command will replaces contactperson with /BGL04/.This is ok.

But above command is failing for "\" character:
cat hh | awk -v con="BGL\04" '{gsub(/contactperson/,con)}1' > final
Above command is replacing contactperson with BGL only.It's truncating the characters which comes after "\" characters.

What I'm looking is after replacement I should get the same string that i uses for replacement

Is there any way to do it, maybe with awk,sed?
Please let me know.
Awaiting for kind responses.

Thanks in Advance.

Regards,
Shareef
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-10-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 572
Code:
cat hh | awk -v con="BGL\\04" '{gsub(/contactperson/,con)}1' > final
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0