one more issue last- sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting one more issue last- sed
# 1  
Old 07-29-2011
one more issue last- sed

hi

i have following sed command

Quote:

cat filename | sed 's/\"\,\"\*\*/' ` echo "\007"` '/' > filename2


this replaces "** in filename1 with octal value 007 filename2

when i put it in script it wont work but it works from command line

my OS is sun OS

---------- Post updated at 06:38 PM ---------- Previous update was at 06:14 PM ----------

i think i use bash shell so it wont work

what should i change to make it work in bash

---------- Post updated at 06:39 PM ---------- Previous update was at 06:38 PM ----------

i think i use bash shell so it wont work

what should i change to make it work in bash

Last edited by er_zeeshan05; 07-29-2011 at 10:22 PM..
# 2  
Old 07-29-2011
I'm guessing that bash's built-in echo command isn't treating \007 the way you'd like. I personally find that echo varies so widely between systems/shells that I avoid using it at all possible costs. I also do not advocate breaking a sed string to "insert" shell generated text -- hard to maintain in my humble opnion.

If I were doing it, I'd tackle it this way as it should work regardless of shell:

Code:
awk 'BEGIN { r=sprintf( "%c", 7 ); } {gsub( "\"\\*\\*", r ); print}' filename >filename2

This replaces the "** with the bell character (7) and then prints the record.

Also, I'm sure someone will chime in that your use of cat is unnecessary as sed can read the input file directly, so I'll point it out:

Code:
sed 's/this/that/g' filename >filename2

No need to cat the file and pipe to sed -- not efficient.

Last edited by agama; 07-29-2011 at 11:06 PM.. Reason: clarification
# 3  
Old 07-29-2011
created a zero byte file

the above statment doesn't work

it creates a zero byte file

Smilie

it a little bit urgent

can someone help

Last edited by er_zeeshan05; 07-29-2011 at 11:23 PM..
# 4  
Old 07-29-2011
What O/S are you using? If you are on Sun OS you should use nawk rather than awk.

Ive tested this both on a SUSE Linux and FreeBSD system and it works as expected; sorry it's not working for you.
# 5  
Old 07-29-2011
i use sun os

so should i replace awk with nawk?
# 6  
Old 07-29-2011
Yes -- I hope that will do the trick. I don't use Sun any more, so I cannot test there, but I remember awk on the Sun as being very limited.
# 7  
Old 07-29-2011
it didn't work
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