Failed to replace string with "sed"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Failed to replace string with "sed"
# 1  
Old 05-07-2006
Failed to replace string with "sed"

Hi folks,

I have the following configuration file:
Code:
tofu:/tmp # cat bitbandConfig.properties 
maestroIp=10.10.10.10
maestroPort=2020
adminPlayPath=<Streaming Agent IP>:2021/streamingGateway/GetPlayList

###This part should not be changed###

adminPlayVODProtocol=http

username=iptv
password=iptv
soapContext=bitband/services/IPTVPlugin

adminFileFormat=.asx

mediaFilePath=
playerJSPath=bitbandPlayer.js

serviceUnitId=1$-$VOD#0$-$VOD

### vs agnostic properties ###
encodingFormats=MPEG-1$-$MPEG_1_SYSTEM#MPEG-2$-$MPEG_2_TRANSPORT#MPEG-4$-$MPEG_4

I'm trying to replace in its last line the string :#MPEG-4$-$MPEG_4 with #MPEG-4$-$MPEG4_H264

I ran a simple sed command:
Code:
sed 's/#MPEG-4\$-\$MPEG_4/#MPEG-4\$-\$MPEG4_H264/g' bitbandConfig.properties

I got 2 problems:
1. The strings were not substituted.
2. The last line was deleted!

What did I do wrong?

Thanks in advance,
Nir
# 2  
Old 05-07-2006
I'll simplify my question:
How can I substitute the string "#MPEG-4$-$MPEG_4" with the string "#MPEG-4$-$MPEG4_H264"?

I tried this :
Code:
tofu:/tmp # echo "#MPEG-4\$-\$MPEG_4" | sed -e 's/"MPEG-4\$-\$MPEG_4"/"MPEG-4\$-\$MPEG4_H264"/'

#MPEG-4$-$MPEG_4

As you can see,I didn't succeed Smilie


Thanks in advance,
Nir
# 3  
Old 05-07-2006
remove the double quotes from your sed command

echo "#MPEG-4\$-\$MPEG_4" | sed -e 's/MPEG-4\$-\$MPEG_4/MPEG-4\$-\$MPEG4_H264/'
# 4  
Old 05-08-2006
Hi sssow,

Thanks!
In the echo command it works fine but when I'm running this command on the file ,the last line which contains the strings is deleted!

Before sed:
Code:
tofu:/tmp # cat bitbandConfig.properties 
maestroIp=10.10.10.10
maestroPort=2020
adminPlayPath=<Streaming Agent IP>:2021/streamingGateway/GetPlayList

###This part should not be changed###

adminPlayVODProtocol=http

username=iptv
password=iptv
soapContext=bitband/services/IPTVPlugin

adminFileFormat=.asx

mediaFilePath=
playerJSPath=bitbandPlayer.js

serviceUnitId=1$-$VOD#0$-$VOD

### vs agnostic properties ###
encodingFormats=MPEG-1$-$MPEG_1_SYSTEM#MPEG-2$-$MPEG_2_TRANSPORT#MPEG-4$-$MPEG_4

After sed:
Code:
tofu:/tmp # sed -e 's/MPEG-4\$-\$MPEG_4/MPEG-4\$-\$MPEG4_H264/' bitbandConfig.properties
maestroIp=10.10.10.10
maestroPort=2020
adminPlayPath=<Streaming Agent IP>:2021/streamingGateway/GetPlayList

###This part should not be changed###

adminPlayVODProtocol=http

username=iptv
password=iptv
soapContext=bitband/services/IPTVPlugin

adminFileFormat=.asx

mediaFilePath=
playerJSPath=bitbandPlayer.js

serviceUnitId=1$-$VOD#0$-$VOD

### vs agnostic properties ###


Why?

Thanks in advance,
Nir
# 5  
Old 05-08-2006
Your sed command seems to work fine.

Code:
[/tmp]$ tail -1 < try
encodingFormats=MPEG-1$-$MPEG_1_SYSTEM#MPEG-2$-$MPEG_2_TRANSPORT#MPEG-4$-$MPEG_4
[/tmp]$ sed 's/#MPEG-4\$-\$MPEG_4/#MPEG-4\$-\$MPEG4_H264/g' try | tail -1
encodingFormats=MPEG-1$-$MPEG_1_SYSTEM#MPEG-2$-$MPEG_2_TRANSPORT#MPEG-4$-$MPEG4_H264

Something to do with your sed ?? Smilie
# 6  
Old 05-08-2006
Hey vino my friend!
Thanks a lot!

It also works now on the file:

Code:
tofu:/tmp # sed 's/#MPEG-4\$-\$MPEG_4/#MPEG-4\$-\$MPEG4_H264/g' bitbandConfig.properties
maestroIp=10.10.10.10
maestroPort=2020
adminPlayPath=<Streaming Agent IP>:2021/streamingGateway/GetPlayList

###This part should not be changed###

adminPlayVODProtocol=http

username=iptv
password=iptv
soapContext=bitband/services/IPTVPlugin

adminFileFormat=.asx

mediaFilePath=
playerJSPath=bitbandPlayer.js

serviceUnitId=1$-$VOD#0$-$VOD

### vs agnostic properties ###
encodingFormats=MPEG-1$-$MPEG_1_SYSTEM#MPEG-2$-$MPEG_2_TRANSPORT#MPEG-4$-$MPEG4_H264

Did you change something in my sed command or your magic hands did the job?

Best regards,
Nir
# 7  
Old 05-08-2006
I did not change anything. Your sed statement worked just fine.

Cheers' !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed command to replace "|" with ^ for all *.dat files in a folder not working

I am trying to use the below sed command to replace all "|" to ^, in a folder had 50 dat files. when i tried with 1 file it worked but when i tried with wild card, is not working. sed -i 's/"|"/\^/g' *.dat Is this the proper way to use sed command thank you very much for help. (3 Replies)
Discussion started by: cplusplus1
3 Replies

2. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

3. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

6. 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

7. Shell Programming and Scripting

Script to search a string which is in between "" and replace it with another character

Hi, I am trying to search a string from a text file which is in between "" (Double Quotes) (Eg: "Unix"), and replace it with a | where ever it is appearing in the text file and save the file. Please help me. -kkmdv (6 Replies)
Discussion started by: kkmdv
6 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. Shell Programming and Scripting

Sed , Replace a "variable text" inside of a statement

Please Help... I am trying to manipulte the following line Before : <user:Account_Password>002786</user:Account_Password> the password is the "variable", i need to delete / omit the password in the file, (it occurs several thousand times) so the tag line looks like After:... (4 Replies)
Discussion started by: jackn7
4 Replies

10. Shell Programming and Scripting

Failed to substitute string with "<>"

Hi folks, I have the following template file: application.filePath.core = /core-RIGHTV/Html/ application.filePath.xbip = /xbip-RIGHTV/Html/ translator.rootContext = /translator_<schame_name>/ I need to substitute the string in the third line "<schema_name>" with $SCHEMA_NAME I ran the... (4 Replies)
Discussion started by: nir_s
4 Replies
Login or Register to Ask a Question