Deleting Doubled Block with sed or awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting Doubled Block with sed or awk
# 1  
Old 07-27-2009
Question Deleting Doubled Block with sed or awk

hi there,

i have a text file like that one:
Quote:
blablabla
blub
bla
Startblabla
texttexttext
texttexttext
texttexttext
Endblabla

Startblabla
texttexttext
texttexttext
texttexttext
Endblabla
blablabla
blub
bla

I like to delete the second block with the Start and End Line!


Quote:
blablabla
blub
bla
Startblabla
texttexttext
texttexttext
texttexttext
Endblabla

blablabla
blub
bla
Does anyone have a idea?

Thanks for your help,

Roland
# 2  
Old 07-27-2009
What have you attempted so far and where do you get stuck?

Regards
# 3  
Old 07-28-2009
At the momentan i have realized it with

Quote:
sed -e '53,84d'
But the lines are very correct.

Than I tried

Quote:
sed -n '/Start*/,/End*/p;/End*/q'
but it just prints that thing I want to delete. Hmmm
And it doesn't test about the dublicity! :-(

Perhaps someone could help me out!

Roland
# 4  
Old 07-28-2009
If Perl is acceptable, you may try something like this:

Code:
perl -0777pe'
  s|(Start.*?End)|$x{$1}++?$/:$1|sge
  ' infile


Last edited by radoulov; 07-28-2009 at 10:00 AM..
# 5  
Old 07-28-2009
You can do something like that :
Code:
awk '(/^Start/ && ++s==2),/^End/ { next } 1 '  inputfile

Inputfile:
Code:
blablabla
blub
bla
Start 1111 blabla
111 texttexttext
111 texttexttext
111 texttexttext
End 1111 blabla

Start 2222 blabla
222 texttexttext
222 texttexttext
222 texttexttext
End 222 blabla
blablabla
blub
bla 
Start 3333 blabla
333 texttexttext
333 texttexttext
333 texttexttext
End 333 blabla
bla

Output:
Code:
blablabla
blub
bla
Start 1111 blabla
111 texttexttext
111 texttexttext
111 texttexttext
End 1111 blabla

blablabla
blub
bla 
Start 3333 blabla
333 texttexttext
333 texttexttext
333 texttexttext
End 333 blabla
bla

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting duplicated chunks in a file using awk/sed

Hi all, I'd always appreciate all helps from this site. I would like to delete duplicated chunks of strings on the same row(?). One chunk is comprised of four lines such as: path name starting point ending point voltage number I would like to delete duplicated chunks on the same... (5 Replies)
Discussion started by: jypark22
5 Replies

2. Shell Programming and Scripting

Need awk/sed command to pull out matching lines from a block

Hi, In order to make our debugging easier in log files, I need this script. My log file will be structured like this : ------Invoking myfile -param:start_time=1371150900000 -param:end_time=1371151800000 for 06/14/2013 <multiple lines here> ..... - Step Sybase CDR Table.0 ended... (3 Replies)
Discussion started by: Lakshmikumari
3 Replies

3. Shell Programming and Scripting

Delete first block of text with sed/awk

Hello, guys! "filename" has blocks with three lines each in this fashion: 93909286 #verified has one bug 10909286 #unverified pending 10909286 #unverified pendingThe above example has duplicate blocks, and I have tried using sed to remove just one block... The... (2 Replies)
Discussion started by: teresaejunior
2 Replies

4. Shell Programming and Scripting

using sed/awk to replace a block of text in a file?

My apologies if this has been answered in a previous post. I've been doing a lot of searching, but I haven't been able to find what I was looking for. Specifically, I am wondering if I can utilize sed and/or awk to locate two strings in a file, and replace everything between those two strings... (12 Replies)
Discussion started by: kiddsupreme
12 Replies

5. Shell Programming and Scripting

deleting lines between patterns using sed or awk

hi, Here is excerpt from my xml file <!-- The custom module to do the authentication for LDAP --> </login-module> <login-module code="com.nlayers.seneca.security.LdapLogin" flag="sufficient"> <module-option... (1 Reply)
Discussion started by: sunrexstar
1 Replies

6. Shell Programming and Scripting

Deleting characters with sed,perl,awk

Input: :: gstreamer :: xine-lib :: xine-lib-extras Output should be: gstreamer xine-lib xine-lib-extras How can it be done with sed or perl? (12 Replies)
Discussion started by: cola
12 Replies

7. Shell Programming and Scripting

Deleting the first column with sed,awk or perl

336 brtr 256 hello Output: brtr hello How can i do this with sed,awk or perl? (5 Replies)
Discussion started by: cola
5 Replies

8. Shell Programming and Scripting

deleting text records with sed (sed paragraphs)

Hi all, First off, Thank you all for the knowledge I have gleaned from this site! Deleting Records from a text file... sed paragraphs The following code works nearly perfect, however each time it is run on the log file it adds a newline at the head of the file, run it 5 times, it'll have 5... (1 Reply)
Discussion started by: Festus Hagen
1 Replies

9. Shell Programming and Scripting

Deleting a line from a file with sed and awk?

cat file.txt fvnuiehuewf ruevhxncvkjrh zxjvurhfuwe jkhvBEGINvfnvf ijrgioe Trying to delete a line that has the pattern "BEGIN" cat sedtest filename=file.txt pattern=BEGIN sed "/^$pattern/d" "$filename" (9 Replies)
Discussion started by: cola
9 Replies
Login or Register to Ask a Question