SED delete string from till problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED delete string from till problems
# 1  
Old 09-01-2010
Data SED delete string from till problems

Hi i have a file which contains 2 lines, line 1 is static data. line 2 is a very large string(over 3000char or much more). in that string are tags which i want to delete.

e.g.
Code:
<order1>123</order1><tag1>data</tag1><new>1</new><order2>124</order2><tag1>data</tag1>

all one one line. now i want to delete the string that starts with <tag1> and end with </tag1>. so that this will be the result:
Code:
<order1>123</order1><new>1</new><order2>124</order2>

what i have is :
Code:
sed -i 's#<tag1>.*</tag1>##g' filename

But what happens that it delete everything between the first <tag1> and the last </tag1>.

So that the result is:
Code:
<order1>123</order1>

you see that everything is delete between the first <tag1> and the last </tag1>

Moderator's Comments:
Mod Comment Please use code tags, ty.

Last edited by zaxxon; 09-01-2010 at 10:40 AM..
# 2  
Old 09-01-2010
Code:
sed 's/<tag1>[^>]*<\/tag1>//g' infile
<order1>123</order1><new>1</new><order2>124</order2>

# 3  
Old 09-01-2010
Hi zaxxon,

Sorry but the code doesn't seem to work. it just leaves the tag1 in the file.
# 4  
Old 09-01-2010
Hm - I just used your example:
Code:
$> cat infile
<order1>123</order1><tag1>data</tag1><new>1</new><order2>124</order2><tag1>data</tag1>
$> sed 's/<tag1>[^>]*<\/tag1>//g' infile
<order1>123</order1><new>1</new><order2>124</order2>

Every tag1-tag is gone with contents between it over the whole line. It works with GNU sed and sed on AIX. No clue why it doesn't work on your box tbh. Maybe someone else got an idea, sorry.
# 5  
Old 09-01-2010
It indeed seems to work with your code and mine little example. But the real file is much longer about 3500 char on one line.

---------- Post updated at 03:38 PM ---------- Previous update was at 03:13 PM ----------

Zaxxon,

I know why it is not working in the real file the <tag> isn't directly followed by the </tag> but it is like this:

Code:
<tag1><cd>value</cd></tag1>

it should delete everything between <tag> and </tag>
# 6  
Old 09-01-2010
It could be that there is some constellation is in this line that the pattern just does not match. Maybe attach the line in a file to a post so people can have a look at it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED help delete characters in a string

Hi Please help me to refine my syntax. I want to delete the excess characters from the out put below. -bash-3.00$ top -b -n2 -d 00.20 |grep Cpu|tail -1 | awk -F ":" '{ print $2 }' | cut -d, -f1 4.4% us now i want to delete the % and us. How wil i do that to make it just 4.4. Thanks (7 Replies)
Discussion started by: redtred
7 Replies

2. UNIX for Dummies Questions & Answers

Delete string between delimiters with sed

Hi, I need to delete all text between "|" delimiters. The line in text file typically looks like this: 1014182| 13728 -rw-r--r-- 1 imac1 staff 7026127 2 okt 2010 |/Users/imac1/Music/iTunes/iTunes Media/Music/Various Artists/We Are the World_ U.S.A. for Africa/01 We Are the World.mp3... (2 Replies)
Discussion started by: andrejm
2 Replies

3. Shell Programming and Scripting

sed delete wildcard within a string

Hi I would like to batch delete the "note" entry from bib files. The start would be defined by "note ={" and the end by "}." (see example bib entry below). I tried the following command which does not have any effect: cat input.bib| sed -e 's/note = {.*}.//' > output.bib Any help would... (2 Replies)
Discussion started by: gerggeismann
2 Replies

4. Shell Programming and Scripting

delete multiline string from file using sed.

Hi, I have file which has the following content... GOOD MORNING **********WARNING********** when it kicks from the kickstart, sshd daemon should start at last. (WHEN KICKING ITSELF, NOT AFTER KICKING). /etc/rc3.d/S55sshd ( run level specification for sshd is 55, now I would want to... (4 Replies)
Discussion started by: skmdu
4 Replies

5. Shell Programming and Scripting

delete strings till specific string

Hello i want to know a way so i can delete all the strings in file from the begning till a specific string (1 Reply)
Discussion started by: modcan
1 Replies

6. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

7. Shell Programming and Scripting

Urgent! Sed/Awk Filter Find Pattern Delete Till End Of Line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (2 Replies)
Discussion started by: rajan_san
2 Replies

8. UNIX for Dummies Questions & Answers

Delete line till certain point

Hi, I have a requirement to delete a line till a certain word. Am not sure how to do it e.g I want to delete till the bold character since start of line. Any help is higly appretiated. (2 Replies)
Discussion started by: inq
2 Replies

9. Shell Programming and Scripting

Using sed to delete string between delimiters

Hi There! I have the following string which i need to convert to i.e. between each occurence of the delimiter ('|' in this case), i need to delete all characters from the '|' to the ':' so that |10,9:12/xxx| becomes |12/xxx| How can i do this using sed? Thanks in advance! (13 Replies)
Discussion started by: orno
13 Replies

10. UNIX for Dummies Questions & Answers

Using sed to delete a string?

Hi all! Here is my problem : I have a string like the following : 20030613170404;BAN_CAV ; starting script Loader.sh on ; 13/06/2003 at ; 17;04;03 I want to eraze all characters located after "Loader.sh", because there are unuseful. I tried to use sed...but it didnt work....i guess i... (1 Reply)
Discussion started by: HowardIsHigh
1 Replies
Login or Register to Ask a Question