07-08-2008
Using sed to substitute first occurrence
I am trying to get rid of some ending tags but I run into some problems.
Ex.
How are you?</EndTag><Begin>It is fine.</Begin><New> Just about
I am trying to get rid of the ending tags, starts with </ and ending with >. (which is </EndTag> and </Begin>)
I tried the following
sed 's/<\/.*>//g' file
It give me the following result which I did not want.
How are you? Just about.
It eliminated everything between you? and Just. There has to be a way to eliminate up to the first >
Second:
Same problem but split over two line.
How are you?</EndTag><Begin>It is fine.</Beg
in><New> Just about the same
Does anyone have an catchall sed command to eliminate everything from </... until it reaches the first > even though it expands mulitple lines.
Thank you.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi, I have a file that looks like this
dasdjasdjoasjdoasjdoa SYN dakspodkapsdka
asdasdasdasdasdasdasd SYN sdfsdfsdfsdfdf
shfishifhsdifhsidhfif fsdfsdfsdfsdfs
sdfsdfsdfsdsdfsdfsdff cercercercerce
sdasdajsdoajsodasodoo FIN dasdaskdpasdda... (4 Replies)
Discussion started by: hcclnoodles
4 Replies
2. UNIX for Dummies Questions & Answers
I am having a problem executing a sed substitute in a file. I have tried alot of different things I found in previous posts, however non seem to work.
I want to substitute this in $FILE:
VALUE=33.4
In the script I have tried the following:
prev=$(awk -F"=" '{ print $2 }' $FILE )
new=$(echo... (16 Replies)
Discussion started by: newbreed1
16 Replies
3. Shell Programming and Scripting
Hi All,
I'm currently using SED to make various changes to some .xml files I'm working on, but I'm stuck on this particular problem.
I want to remove '<placeholder>element-name</placeholder>' from the following:
<heading>Element <placeholder>element-name</placeholder> not... (2 Replies)
Discussion started by: Steve_altius
2 Replies
4. UNIX for Dummies Questions & Answers
I'm using sed to perform a simply search and replace. The typical data is:
<fig><image href="Graphics/BAV.gif" align="left" placement="break"
I need to replace the value in the first set of quotes, keeping the remainder of the line the same. Thus:
<fig><image href="NEW_VALUE" align="left"... (3 Replies)
Discussion started by: Steve_altius
3 Replies
5. Shell Programming and Scripting
I am trying to do what I thought should be a simple substitution, but I can't get it to work.
File:
Desire output:
I thought I'd start with a sed command to remove the part of the header line preceding the string "comp", then go on to remove the suffix of the target string (e.g. ":3-509(-)"),... (3 Replies)
Discussion started by: pathunkathunk
3 Replies
6. UNIX for Dummies Questions & Answers
How to find last occurrence of a keyword in a file using sed. (4 Replies)
Discussion started by: nexional
4 Replies
7. Shell Programming and Scripting
Assume a string that contains one or multiple occurrences of three different keywords (abbreviated as "kw"). I would like to replace kw2 with some other string, say "qux". Specifically, I would like to replace that occurrence of kw2 that is the first one that is preceded by kw1 somewhere in the... (4 Replies)
Discussion started by: M Gruenstaeudl
4 Replies
8. UNIX for Dummies Questions & Answers
I have the following script:
sed '/string1/,/string2/!d' infile
I want to apply the script to the first occurrence only. I have tried
sed '0,/string1/,/string2/!d' infile
Of course, that does not work
Any help will be greatly appreciated (12 Replies)
Discussion started by: Xterra
12 Replies
9. Shell Programming and Scripting
Hi, i have file file.txt with data like:
START
03:11:30 a
03:11:40 b
END
START
03:13:30 eee
03:13:35 fff
END
jjjjjjjjjjjjjjjjjjjjj
START
03:14:30 eee
03:15:30 fff
END
ggggggggggg
iiiiiiiiiiiiiiiiiiiiiiiii
I want the below output
START (13 Replies)
Discussion started by: Jyotshna
13 Replies
10. UNIX for Beginners Questions & Answers
hi all,
i'd like to modify a file with sed , i want to substuite a char "-" with "/"
how can i do this?
Thanks for all
regards
Francesco (16 Replies)
Discussion started by: Francesco_IT
16 Replies