sed error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed error
# 1  
Old 04-28-2008
sed error

in a bash shell I have the following

S00="BLOCK-NAMES /ELM1 /SAUT0 /FIT00 FOR ELMT,SAMPLE,FIT"
S01="BLOCK-NAMES /ELM1 /SAUT0 /FIT01 FOR ELMT,SAMPLE,FIT"

sed "s/'$S00'/'$S00'/g" pb206.cnt > tmp

sed commplains and says
sed: -e expression #1, char 29: Unknown option to `s'

Can anybody help?
Thank you!!!
# 2  
Old 04-28-2008
Try this
Code:
sed 's/$S00/$S01/g' pb206.cnt > tmp

instead of
Code:
sed "s/'$S00'/'$S00'/g" pb206.cnt > tmp

# 3  
Old 04-28-2008
Thank you Shivdatta, it doesn't complain anymore but it does not replace the string!
# 4  
Old 04-28-2008
You are replacing a string with the same string, so it's quite possible that it's replacing it, but there is no way to tell.

What exactly would you expect the result to be like?
# 5  
Old 04-28-2008
If in case u are trying to replace FIT00 by FIT01 then if this helps

sed 's/\(.*\)FIT00\(.*\)/\1FIT01\2/g' filename
# 6  
Old 04-28-2008
of course the strings are different:
here is the script

S00="BLOCK-NAMES /ELM1 /SAUT0 /FIT00"
S01="BLOCK-NAMES /ELM1 /SAUT0 /FIT01"
S02="BLOCK-NAMES /ELM1 /SAUT0 /FIT02"
S03="BLOCK-NAMES /ELM1 /SAUT0 /FIT03"

sed 's/$S00/$S01/g' pb206.cnt > tmp1
sed 's/$S00/$S02/g' pb206.cnt > tmp2
sed 's/$S00/$S03/g' pb206.cnt > tmp3

but tmp1, tmp2 and tmp3 are the same as pb206.cnt (which contains S00)
# 7  
Old 04-28-2008
Shivdatta: Actually you probably mean

Code:
sed 's/FIT00/FIT01/g' filename

Your expression will replace only one occurrence (the last I believe) because of the wildcards which make it match the whole line.

But I guess what's asked for is really

Code:
sed "s%$S00%$S01%g" file

Single quotes force the strings to be taken literally; no quotes will give you a syntax error for many complex strings. To interpolate a variable into a string, put it in double quotes.

Of course, if you meant the substitution to contain literal single quotes, put them back in.

The "unknown option to s" error happens because the interpolated string contains slashes. Sed has no way to know which slashes were interpolated (this happens in the shell, before sed executes) so you need to use a different separator than the slash. (Fortunately in this case you know there are no percent signs in these variables. It's tougher when you can't know in advance whether or not a particular character could be included in a variable.)

Last edited by era; 04-28-2008 at 09:50 AM.. Reason: Explain quoting and cause of error message
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

2. Shell Programming and Scripting

sed Error

I am using this command: sed 's///g' file1 I want to keep only Arabic Characters and remove all others. I get this error: sed: -e expression #1, char 17: Invalid collation character (3 Replies)
Discussion started by: Viernes
3 Replies

3. Shell Programming and Scripting

sed returns error "sed: -e expression #1, char 18: unterminated `s' command"

Hello All, I have something like below LDC100/rel/prod/libinactrl.a LAA2000/rel/prod/libinactrl.a I want to remove till first forward slash that is outputshould be as below rel/prod/libinactrl.a rel/prod/libinactrl.a How can I do that ??? (8 Replies)
Discussion started by: anand.shah
8 Replies

4. UNIX for Dummies Questions & Answers

sed error

Hi, I'm trying to go through a file and replace in each word (separated by new lines if it matters) the first occurrence of a vowel with #. works, but of course it replaces all vowels. However, removing the /g produces an error that says: Can anyone help?? (1 Reply)
Discussion started by: justOne21
1 Replies

5. Shell Programming and Scripting

SED error

Hi, I am trying to write an SED script to extract some strings from each line of a file and print it into another file. The sample input looks like this. AVE_LOC_ADDED <= 1.1429: 0 (28035.0/53.0) <IG:0.09933947301390625; GR:0.21494375103088412; WeightedGR:6679.592007035755>... (4 Replies)
Discussion started by: sandeepk1611
4 Replies

6. Shell Programming and Scripting

Error in sed

Hello, I want to remove .txt from every file name: for file in *.txt; des=$(echo $file | sed 's/\.txt//'); mv "$file" "$des"; done but this gives me: bash: syntax error near unexpected token `des=$(echo $file | sed 's/\.txt//')' I understand that there's other ways of doing this... (1 Reply)
Discussion started by: juliette salexa
1 Replies

7. Shell Programming and Scripting

sed ERROR

Hi Leute Kann mir bitte jemand diesen Fehler rerklären? Ohne Zuweisung gehts und es kommt der modifizierte String raus. Weise ich es einem String zu kommt dieser Fehler. Was mache ich da flasch? 0:521:root@pendrive /media/disk/system_setup # STRING=/mnt/new/path 0:522:root@pendrive... (3 Replies)
Discussion started by: latenite
3 Replies

8. Shell Programming and Scripting

sed error

hi guys!! I am new to shell script.. here is what i want do, i want to search original string in export.txt file which is: export mib =/opt/old_mib/ i want to replace it by export mibs =/opt/new_mibs/ i tried sed -e 's/export mib =/opt/old_mib//export mibs =/opt/new_mibs//g' ... (4 Replies)
Discussion started by: allrise123
4 Replies

9. Shell Programming and Scripting

sed error : Syntax error: redirection unexpected

My script is throwing the error 'Syntax error: redirection unexpected' My line of code.. cat nsstatustest.html | sed s/<tr><td align="left">/<tr><td align="left" bgcolor="#000000"><font color="white">/ > ztmp.Ps23zp2s.2-Fpps3-wmmm0dss3 HTML tags are getting in the way but they're needed to... (3 Replies)
Discussion started by: phpfreak
3 Replies

10. Shell Programming and Scripting

Error when using sed

Hi, I have a input file with following contents ---------------------------------------------------------Run Number: 1----------------------------------------------------------- test_run -layout test_vaal -i |Started|05/28/2007 02:19:30|TEST|8651... (2 Replies)
Discussion started by: Raghuram.P
2 Replies
Login or Register to Ask a Question