one more issue last- sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting one more issue last- sed
# 8  
Old 07-30-2011
This is a real hack, but I cannot think of anything else to try without having a Sun to run the test on myself. Try this, but see the note below before you change your script:

Code:
awk '{gsub( "\"\\*\\*", "^G" ); print}' filename >filename2

The ^G is a control character entered using an editor, NOT the two characters ^ and G as appear here. Using vi to edit the script, and while in insert mode, type CTL-V and CTL-G to insert a control-g character into the file. You should see ^G reprented by vi. I'm not a fan of putting control characters into a script like this, but if it's the only way then one does what works.


If this doesn't work, then I'm out of suggestions. Hoping for the best, and sorry if you're left with it broken.
# 9  
Old 07-30-2011
e flag in echo

i just added -e in echo option in which helped to solve the problem
# 10  
Old 07-30-2011
Quote:
cat filename | sed 's/\"\,\"\*\*/' ` echo "\007"` '/' > filename2
You have a space there between single quote and backtick. That causes error -- sed complains about unterminated s command. There is no need for echo or escaping quotes or comma.
Try this:
Code:
sed  's/","\*\*/\x07/' filename > filename2

And check with 'od':
Code:
$ echo '"blah","**ddsa","das**","dad"' | sed  's/","\*\*/\x07/'
"blahddsa","das**","dad"
$ echo '"blah","**ddsa","das**","dad"' | sed  's/","\*\*/\x07/'  | od -c
0000000   "   b   l   a   h  \a   d   d   s   a   "   ,   "   d   a   s
0000020   *   *   "   ,   "   d   a   d   "  \n
0000032
$ echo '"blah","**ddsa","das**","dad"' | sed  's/","\*\*/\x07/'  | od -x
0000000 6222 616c 0768 6464 6173 2c22 6422 7361
0000020 2a2a 2c22 6422 6461 0a22
0000032



Quote:
Originally Posted by agama
but if it's the only way then one does what works
You can insert a control character with crtl-v on the command line, no need to save it and use vi:
Code:
sed  's/","\*\*/^G/' filename > filename2

just type ctrl-v ctrl-g when typing the command.

Last edited by mirni; 07-30-2011 at 08:13 PM..
This User Gave Thanks to mirni For This Post:
# 11  
Old 07-30-2011
Quote:
Originally Posted by mirni
You have a space there between single quote and backtick. That causes error -- sed complains about unterminated s command. There is no need for echo or escaping quotes or comma.
Try this:
Nice catch -- I completely missed the space.

Quote:
Code:
sed  's/","\*\*/\x07/' filename > filename2

Thanks -- I read the man page and found no reference to being able to use \xXX. I tried \0xXX which didn't work and am glad to be able to take something new away from this thread.

Quote:
You can insert a control character with crtl-v on the command line, no need to save it and use vi
True. I omitted that as the OP indicated it wasn't working from a script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed issue

I'm trying to change a date in a couple of large files using SED. The problem is when I use the -n parameter, it doesn't actually change the file. When I leave out the -n, it sends the whole file to the screen, but it does appear to change it. The problem is, these files are very large and it... (8 Replies)
Discussion started by: Drenhead
8 Replies

2. Shell Programming and Scripting

sed issue

I can't get this code to work, could I get some help... sed -i '' "s:${shLogpath1}${cell}:${shLogpath2}${cell}:g" test.txt Any Ideas, I think I need to separate the variables some how? (2 Replies)
Discussion started by: digitalviking
2 Replies

3. Shell Programming and Scripting

sed issue

Hi guys. Can somone advise as to what the problem is with the following sed command? 1) read -p "Please enter new username you wish to replace old: " new_username sed "s/$username/$new_username/" information_file ;; This is one of the case statements included but I'm... (1 Reply)
Discussion started by: jjb1989
1 Replies

4. Shell Programming and Scripting

Sed Issue

Hi, I am trying to use 3 sed statements in a shell script, but it get foll error. sed : garbage after command. If I use only two sed statements, the script works well. Is there any restriction for sed usage or is there some catch which I am missing. Sample Script is as follows : ... (3 Replies)
Discussion started by: sameersalve
3 Replies

5. Shell Programming and Scripting

Issue with Sed Command

Hello , I am trying to replace a word :: complete to Failed . work: complete Sed command which i am using is given below :: sed s/work: complete/Failed/g temp1.txt > temp2.txt (Sed command is grabled if i use the above .. because of space which is there between work: and complete. I... (6 Replies)
Discussion started by: raghav1982
6 Replies

6. Shell Programming and Scripting

sed issue

Hi All I'm getting this error while executing a sed script sed: 0602-404 Function /</ i\ File from New Cube: cannot be parsed. sed "/</ i\ File from New Cube: />/ i\ File from Old Cube:" difference1.txt > Difference.txt I've a file like this < Y2008 Dec ..... .... ... 345 I want... (6 Replies)
Discussion started by: Celvin VK
6 Replies

7. Shell Programming and Scripting

Sed Issue....

Can someone help me "port" this to AIX sed? sed '/nas/{n;s/true/false/}' I know it doesn't like the ; but i don't know how else to do it.... never had to sed on an AIX box :D (7 Replies)
Discussion started by: DeviousPete
7 Replies

8. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

9. UNIX for Dummies Questions & Answers

SED Issue

Can anyone tell me ...on the below listed command cat /mnt/winbox/list_measurement/ds1c/ds1_f.rome_27A03A 2>> error_log | sed -e '1,3d;s/^/27A03A,/' | sed -e "s#\(.*\)#\1 ,$(date +%Y-%m-%d)#g" > /SBS/ds1_f.rome_27A03A The outcome is this: ,2005-08-29 Forestdale,3:02 am MON AUG 29,... (9 Replies)
Discussion started by: Redg
9 Replies

10. Shell Programming and Scripting

Issue with sed in script

I have a loop in a script that is given me an error but, when I do it on the command line it works perfectly. The sed statement has to use the variables from a file so the file is partitioned correctly. I am running on HP: <Begin error>: + cat /u01/bteam/CNAM/1121/.partition + read line + +... (3 Replies)
Discussion started by: bthomas
3 Replies
Login or Register to Ask a Question