sub option of awk command not working with "\" character.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sub option of awk command not working with "\" character.
# 1  
Old 06-10-2008
MySQL 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
# 2  
Old 06-10-2008
Code:
cat hh | awk -v con="BGL\\04" '{gsub(/contactperson/,con)}1' > final

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

5. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

6. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. Shell Programming and Scripting

How can I use a pipe operator in a variable: OPTION="| command"?

I have a string of commands I am piping some data through and I want to allow command line switches to select which commands are used. I want to do something like this: OPTION="| command3" command1 -a -b c.txt | command2 -d -e $OPTION >result.txt I want to do it that way because OPTION may be... (1 Reply)
Discussion started by: KenJackson
1 Replies

8. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

9. UNIX for Dummies Questions & Answers

How to pass option with "at" command?

Hi, I've got a ksh script that expects a file name as a parameter. The script in turn executes another command "sas", after assigning some environment variables, passing that file name down the line. From the command prompt, all works swell if I type "sasbatch filename". However, if I try... (3 Replies)
Discussion started by: bd9439
3 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question