replace word with using "sed" not work...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace word with using "sed" not work...
# 1  
Old 02-27-2007
replace word with using "sed" not work...

Hi,

I have a xml text file with the following data, I would like replace F0</Number> to F</Number> only. i used sed to replace, but it not work!! anyone can help?


Code:
<Number>11 20 03 22 23 21 91 00 F0</Number>
<Number>12 20 03 20 99 21 91 20 F0</Number>
<Number>10 21 03 21 78 21 92 27 F0</Number>

sed 's/F0</Number>/F</Number>/g' $file


Thanks!!
# 2  
Old 02-27-2007
Change the separator...
Code:
sed 's!F0</Number>!F</Number>!g' $file

# 3  
Old 02-27-2007
Quote:
Originally Posted by Ygor
Change the separator...
Code:
sed 's!F0</Number>!F</Number>!g' $file

its not work....(already run the sed command line no error). The result is the same..
# 4  
Old 02-28-2007
sed not working

Hi,

Instead of changing F0<Number> to F<Number>
you can do a a replacement of FO with F
sed 's/FO/F/g' file.xml

if thats is not the requirement then we should be careful while using special characters

Regards,
Rakesh UV
# 5  
Old 02-28-2007
Code:
>sed 's;F0</Number>;F</Number>;g' file
<Number>11 20 03 22 23 21 91 00 F</Number>
<Number>12 20 03 20 99 21 91 20 F</Number>
<Number>10 21 03 21 78 21 92 27 F</Number>

# 6  
Old 02-28-2007
Quote:
Originally Posted by matrixmadhan
Code:
>sed 's;F0</Number>;F</Number>;g' file
<Number>11 20 03 22 23 21 91 00 F</Number>
<Number>12 20 03 20 99 21 91 20 F</Number>
<Number>10 21 03 21 78 21 92 27 F</Number>

i am not sure...is it my file is xml format, the sed command not work.

sed 's;F0</Number>;F</Number>;g' file

if I used below, it work
sed 's; <Number>11 20 03 22 23 21 91 00 0F</Number>; <Number>11 20 03 22 23 21 91 00 F</Number>;g' file


Anyway, my file with more than 10,000 line and it waste time to manual to put the <number> information into the script.

any idea?
# 7  
Old 02-28-2007
Quote:
Originally Posted by happyv
i am not sure...is it my file is xml format, the sed command not work.

sed 's;F0</Number>;F</Number>;g' file

if I used below, it work
sed 's; <Number>11 20 03 22 23 21 91 00 0F</Number>; <Number>11 20 03 22 23 21 91 00 F</Number>;g' file


Anyway, my file with more than 10,000 line and it waste time to manual to put the <number> information into the script.

any idea?
Based on the sample file posted, command was posted.

Could you please post the exact command you ran and the output that you got? Smilie

I had tested and then only posted, sure the command should work Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add the word "prefix" to beginning of line using sed

SUSE linux bash shell this works test -d /tmpp && echo "directory exists" || echo "directory doesn't exists" |sed -e "s/^/prefix /" prefix directory doesn't exists but why doesn't this work? test -d /tmp && echo "directory exists" || echo "directory doesn't exists" |sed -e... (3 Replies)
Discussion started by: snoman1
3 Replies

2. Shell Programming and Scripting

How do i replace a word ending with "key" using awk excpet for one word?

echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} | awk 'gsub(/^|abc,|$/,"") {print}' Required output {grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies

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

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

5. Shell Programming and Scripting

Interesting question - Search and replace the word after sign "="

Hi Guys, Req your help in searching and replacing the word that comes after equals(=) symbol I would like to replace the sting in bold with a string in variable. d=ABCDF8C44C22 # grep -i NIM_MASTERID ${_NIMINFO} export NIM_MASTERID=00CDF8C44C00 I'm looking to replace any word that... (4 Replies)
Discussion started by: ajilesh
4 Replies

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

7. Shell Programming and Scripting

Extract Part of a "Word", using AWK or SED????

I have been lurking on this forum for some time now and appreciate Everyone's help. I need to find a way to get the SystemID from this XML file. The file is much larger than just this one line but I can grep and get this line Printed. But really just need the "systemid". <test123: prefintem... (9 Replies)
Discussion started by: elbombillo
9 Replies

8. Shell Programming and Scripting

Can "sed" substitute word on a specific line?

Hello experts, I know line number of the word I want to replace. Can "sed" substitute word on a specific line? As well, can sed substitute words inside a specific patten. ex. <word>lalala</word> #replace anything between <word> and </word> minifish (2 Replies)
Discussion started by: minifish
2 Replies
Login or Register to Ask a Question