Sponsored Content
Top Forums Shell Programming and Scripting How can i delete the content between all the occurences of two strings using sed or awk command Post 302548011 by satheeshkumar on Wednesday 17th of August 2011 08:51:34 AM
Old 08-17-2011
How can i delete the content between all the occurences of two strings using sed or awk command

Hi. I have to delete the content between all the occurrences of the xml tags in a single file.

For example:

* The tags <script>.....................</script> occurs more than once in the same file.

* It follows tagging rules meaning a start tag will be followed by an end tag. Will not have two continuous similar opening tags.

* But the tags are not necessarily in separate lines.

I used the below script which has deleted just the first occurrence in the file.
Code:
sed -e "s/ <script>*?<\/script>//g" $INF > $OUTF

Please help me in doing this. Since i have to process huge amount of data, more efficient method would be better.

If there is any other way apart from sed and awk that would also be better.

Last edited by Franklin52; 08-17-2011 at 10:38 AM.. Reason: Please use code tags for data and code samples, thank you
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting occurences of different strings in a file

Hi, i'd like to know if the following is possible with a shell script, and can't find the answer in the search. Suppose i have a logfile build like this: # 8 :riuyzp1028 # 38 : riuyzp1028 # 25 : riuyvzp1032 # 30 : nlkljpa0202 # 1 : nlklja0205 # 38 : riuyzp1028 # 25 :... (4 Replies)
Discussion started by: Freerider
4 Replies

2. Shell Programming and Scripting

sed, awk [TAG]$content[/TAG] How to get var in $content in textfile?

Hello, I got a Qstion. Im posting to a phpbb forum with bash and curl.. i have a text file with the following tags that i post to the forum: $var1 $var2 $var3 How can i with sed or awk put var content from shell script between the ... in the... (7 Replies)
Discussion started by: atmosroll
7 Replies

3. Shell Programming and Scripting

awk/sed/perl command to delete specific pattern and content above it...

Hi, Below is my input file: Data: 1 Length: 20 Got result. Data: 2 Length: 30 No result. Data: 3 Length: 20 (7 Replies)
Discussion started by: edge_diners
7 Replies

4. Shell Programming and Scripting

Using Bash/Sed to delete between identical strings

Hi. I'm hoping that someone can help me with a bash script to delete a block of lines from a file. What I want to do is delete every line between two stings that are the same, including the line the first string is on but not the second. (Marked lines to match with !) For example if I... (2 Replies)
Discussion started by: Zykr
2 Replies

5. Shell Programming and Scripting

Delete 2 strings from 1 line with sed?

Hi guys, I wonder if it's possible to search for a line containing 2 strings and delete that line and perhaps replace the source file with already deleted line(s). What I mean is something like this: sourcefile.txt line1: something 122344 somethin2 24334 45554676 line2: another something... (6 Replies)
Discussion started by: netrom
6 Replies

6. Shell Programming and Scripting

Count the occurences of strings

I have some text files in a folder f1 with 10 columns. The first five columns of a file are shown below. aab abb 263-455 263 455 aab abb 263-455 263 455 aab abb 263-455 263 455 bbb abb 26-455 26 455 bbb abb 26-455 26 455 bbb aka 264-266 264 266 bga bga 230-232 230 ... (10 Replies)
Discussion started by: gomez
10 Replies

7. Shell Programming and Scripting

sed - delete content inside tags multiline

I need that a certain part of the content below excluded ==Image Gallery== followed by <gallery> and the content until </gallery> test SED1 ==Image Gallery== <gallery> Image:car1.jpg| Car 1<sup>1</sup> Imagem: car2.jpg| Car2<sup>2</sup> </gallery> test SED2 ==Image... (5 Replies)
Discussion started by: dperboni
5 Replies

8. UNIX for Advanced & Expert Users

Perl regex problem on strings with several occurences of one char

Hi all, i have the following line in a record file : retenu=non demande=non script=#vtbackup /path=/save/backup/demande position=140+70 and i want to use Perl regex to have the following output key : "retenu" value : "non" key : "demande" value "non" key : "script" value :... (2 Replies)
Discussion started by: Fundix
2 Replies

9. Shell Programming and Scripting

awk to delete content before and after a matched pattern

Hello, I have been trying to write a script where I could get awk to delete data before and after a matched pattern. For eg Raw data Start NAME = John Age = 35 Occupation = Programmer City = New York Certification Completed = No Salary = 80000 End Start NAME = Mary Age = 25... (2 Replies)
Discussion started by: sidnow
2 Replies

10. UNIX for Beginners Questions & Answers

Sed, awk or another bash command to modify string with the content of another file

Hello everybody, I would like modify some strings using sed or another command line with the content file. For example: - {fqdn: "server-01" , ip: "server-01"} - {fqdn: "server-02" , ip: "server-02"} - {fqdn: "server-03" , ip: "server-03"} - {fqdn: "server-04" , ip: "server-04"} My... (4 Replies)
Discussion started by: dco
4 Replies
M_TAG(9)						   BSD Kernel Developer's Manual						  M_TAG(9)

NAME
m_tag, m_tag_get, m_tag_free, m_tag_prepend, m_tag_unlink, m_tag_delete, m_tag_delete_chain, m_tag_delete_nonpersistent, m_tag_find, m_tag_copy, m_tag_copy_chain, m_tag_init, m_tag_first, m_tag_next -- mbuf tagging interfaces SYNOPSIS
#include <sys/mbuf.h> struct m_tag * m_tag_get(int type, int len, int wait); void m_tag_free(struct m_tag *t); void m_tag_prepend(struct mbuf *m, struct m_tag *t); void m_tag_unlink(struct mbuf *m, struct m_tag *t); void m_tag_delete(struct mbuf *m, struct m_tag *t); void m_tag_delete_chain(struct mbuf *m, struct m_tag *t); void m_tag_delete_nonpersistent(struct mbuf *); struct m_tag * m_tag_find(struct mbuf *m, int type, struct m_tag *t); struct m_tag * m_tag_copy(struct m_tag *m); int m_tag_copy_chain(struct mbuf *to, struct mbuf *from); void m_tag_init(struct mbuf *m); struct m_tag * m_tag_first(struct mbuf *m); struct m_tag * m_tag_next(struct mbuf *m, struct m_tag *t); DESCRIPTION
The m_tag interface is used to ``tag'' mbufs. FUNCTIONS
m_tag_get(type, len, wait) Allocate an mbuf tag. type is one of the PACKET_TAG_ macros. len is the size of the data associated with the tag, in bytes. wait is either M_WAITOK or M_NOWAIT. m_tag_free(t) Free the mbuf tag t. m_tag_prepend(m, t) Prepend the mbuf tag t to the mbuf m. t will become the first tag of the mbuf m. When m is freed, t will also be freed. m_tag_unlink(m, t) Unlink the mbuf tag t from the mbuf m. m_tag_delete(m, t) The same as m_tag_unlink() followed by m_tag_free(). m_tag_delete_chain(m, t) Unlink and free mbuf tags beginning with the mbuf tag t from the mbuf m. If t is NULL, m_tag_delete_chain() unlinks and frees all mbuf tags associated with the mbuf m. m_tag_delete_nonpersistent(m) Unlink and free all non persistent tags associated with the mbuf m. m_tag_find(m, type, t) Find an mbuf tag with type type after the mbuf tag t in the tag chain associated with the mbuf m. If t is NULL, search from the first mbuf tag. If an mbuf tag is found, return a pointer to it. Otherwise return NULL. m_tag_copy(t) Copy an mbuf tag t. Return a new mbuf tag on success. Otherwise return NULL. m_tag_copy_chain(to, from) Copy all mbuf tags associated with the mbuf from to the mbuf to. If to already has any mbuf tags, they will be unlinked and freed beforehand. Return 1 on success. Otherwise return 0. m_tag_init(m) Initialize mbuf tag chain of the mbuf m. m_tag_first(m) Return the first mbuf tag associated with the mbuf m. Return NULL if no mbuf tags are found. m_tag_next(m, t) Return the next mbuf tag after t associated with the mbuf m. Return NULL if t is the last tag in the chain. CODE REFERENCES
The mbuf tagging interfaces are implemented within the file sys/kern/uipc_mbuf2.c. The PACKET_TAG_ macros are defined in the file sys/sys/mbuf.h. SEE ALSO
intro(9), malloc(9), mbuf(9) BUGS
The semantics of the term "persistent tag" are vague. BSD
September 7, 2004 BSD
All times are GMT -4. The time now is 08:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy