escape characterz...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting escape characterz...
# 1  
Old 11-03-2006
escape characterz...

hey
i wanted to know if there is some single unix command to replace all the character escape sequences with their "C" values in a string...
The only way i know is repetatively kepp using the grep command for each one.
# 2  
Old 11-03-2006
put some example !!!
# 3  
Old 11-04-2006
EXample...

Whenever we have a \" we need to replace it with a ",if s[j]=='\\' and s[j+1]=='n' then replace it by='\n'..
Character Escape Sequence
" \"
' \'
? \?
\ \\
BEL \a
BS \b
FF \f
NL \n
CR \r
HT \t
VT \v
# 4  
Old 11-06-2006
An awk solution :
Code:
BEGIN {
   c["\""] = "\""; c["'"] = "'" ; c["?"] = "?" ; c["\\"] = "\\";
   c["a"]  = "\a"; c["b"] = "\b"; c["f"] = "\f"; c["\n"] = "\n";
   c["r"]  = "\r"; c["t"] = "\t"; c["v"] = "\v";
}
{
   old_line = $0;
   new_line = "";
   while (match (old_line, /\\/)) {
     new_line = new_line substr(old_line, 1, RSTART-1) c[substr(old_line, RSTART+1, 1)];
     old_line = substr(old_line, RSTART+2);
   }
   new_line = new_line old_line;
   print new_line;
}

To convert a file :
Code:
awk -f awk_script input_file > output_file

I hope that there is a simplest way to do the work Smilie

Jean-Pierre.
# 5  
Old 11-06-2006
escape..

I want the code in shell script using the sed command..
i think it looks like
echo madhu\\shri\sgar\mi\ | sed -e 's/"\\"/"\"/g' -e ' s/\"/"/' -e 's/\'/'/' -e ' s/\?/?/' -e 's/\a/BEL/' -e ' s/\b/BS/' -e 's/\f/FF/' -e ' s/\n/NL/' -e 's/\r/CR/' -e 's/\t/HT/' -e 's/\v/VT/'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Escape Sequences

Hi Gurus, Escape sequences \n, \t, \b, \t, \033(1m are not working. I just practiced these escape sequences. It worked first. Later its not working. Also the command - echo inside the script editor shows as shaded by a color. Before that echo inside the script editor wont show like this.... (4 Replies)
Discussion started by: GaneshAnanth
4 Replies

2. Shell Programming and Scripting

Auto escape script to escape special chars in script args

This is a bit off the wall, but I often need to run scripts where there are argument values that contain special characters. For example, $ ./process.exe -t M -N -o temp.mol.s -i ../molfiles/N,N\',N\'\'-trimethylbis\(hexamethylene\)triamine.mol && sfile_space_to_tab.sh temp.mol.s temp.s It... (1 Reply)
Discussion started by: LMHmedchem
1 Replies

3. Shell Programming and Scripting

Escape characters

i am executing script from A server which will execute the script in B server , as below. ssh A 'ssh B echo 'select * from testing where name ='test'' i am getting the below output. select * from testing where name=test but i need the output where clause with quotes , tried with... (3 Replies)
Discussion started by: expert
3 Replies

4. Shell Programming and Scripting

Escape ' in awk

I am trying to escape single quote in awk, but could not: awk ' BEGIN{ fstr="COMPRESS('Y','N')" } { substr($1,len-3,4)~/_IND/ len=length($1) if(substr($1,len-3,4)~/_IND/) printf("%-32s%-14s%-5s%-14s\n",$1,$2,$3,$fstr,$4,$5,$6,$7) } ' tt.txt > out.log Error: awk: Field... (8 Replies)
Discussion started by: ysvsr1
8 Replies

5. Shell Programming and Scripting

Escape and combination

Hi I have 2 files like: file1 a 12 b 1 a 3 file2 a 9 c 0 a 8 and i would like to get a 12 a 9 a 3 a 8 i can do it with grep and paste with 3 lines. I tried to combine using: (3 Replies)
Discussion started by: Dedalus
3 Replies

6. Shell Programming and Scripting

How to escape from the shell

In a Script I need to push several messages to a function. My problem here is: I have to print the string v$LOCK on the resulting line which spits out the message. What I want here is not printing the contents of $LOCK I want to escape the shell and printout v$LOCK on the line. But don't know how... (3 Replies)
Discussion started by: sdohn
3 Replies

7. Shell Programming and Scripting

escape sequence for $

Hi all, I have a requirement where the variable name starts with $, like $Amd=/home/student/test/ How to work wit it? can some one help me, am in gr8 confusion:confused: (5 Replies)
Discussion started by: shreekrishnagd
5 Replies

8. Shell Programming and Scripting

escape chracters

hi, how to echo \\ in unix ie echo the path \\dir1\dir2\\dir3 thanks, Sam (7 Replies)
Discussion started by: sam99
7 Replies

9. Shell Programming and Scripting

Escape character

Hi , I want to change space to ' in my script. I tried doing this, sed 's/ /\'/g' filename but i could not get it. can some one help me please. Thanks, Deepak (4 Replies)
Discussion started by: deepakpv
4 Replies

10. Shell Programming and Scripting

escape characters..

hey i want to know the unix commands to replace all the character escape sequences with their "C" values in a string... thanks in advance..! Regards, Sharanya (9 Replies)
Discussion started by: sharsin2001
9 Replies
Login or Register to Ask a Question