remove unwanted specific line range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove unwanted specific line range
# 1  
Old 03-10-2011
remove unwanted specific line range

Hello everyone...I have large txt file and I would like to remove unwanted specific line.
My data is like this:

Quote:
No. Time
38 1.292367
Frame

0000 00 04 45 00 ..."Z.... l...E.
0010 01 05 0a 01 ...L@.@..?......

Reassembled

0000 48 4f 4b 0d HTTP/1.1 200 OK.
0010 0a 30 20 4e .Date: Sat, 20 N

No. Time
61 1.416360
Frame
0000 00 04 e2 22 ..."Z.... l...E.
...
Reassembled
0000 48 54 54 2c HTTP/1.1 200 OK.
So I would like to remove from line below No. until line reassambled like this:
Quote:
No. Time
0000 48 4f 4b 0d HTTP/1.1 200 OK.
0010 0a 30 20 4e .Date: Sat, 20 N
No. Time
0000 48 54 54 2c HTTP/1.1 200 OK.
Thanks...
# 2  
Old 03-10-2011
Try:
Code:
perl -p0e 's/(?<=No\. Time\n).*?Reassembled\n//sg;s/\n\n/\n/g' file

# 3  
Old 03-10-2011
Hi taxi,

An option using sed:
Code:
sed -e '/No. Time/,/Reassembled/d;s/^$/No. Time/' taxi
No. Time
0000 48 4f 4b 0d HTTP/1.1 200 OK.
0010 0a 30 20 4e .Date: Sat, 20 N
No. Time
0000 48 54 54 2c HTTP/1.1 200 OK.

Regards
# 4  
Old 03-10-2011
thank you for your reply. Based on my input, both given output that I have mention earlier. But my original file just not No. and Time only, but other text with space each other.
No._5space_Time_8space_Source_16space_Destination__11space__Protocol Info


I'm try to put all string in line No., but it's remove this line.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 03-10-2011 at 04:18 PM.. Reason: code tags, please!
# 5  
Old 03-10-2011
taxi,
If the input is something like this (and the headers always begin with "No"...):
Code:
No.     Time        Source                Destination           Protocol Info
38 1.292367
Frame

0000 00 04 45 00 ..."Z.... l...E.
0010 01 05 0a 01 ...L@.@..?......

Reassembled

0000 48 4f 4b 0d HTTP/1.1 200 OK.
0010 0a 30 20 4e .Date: Sat, 20 N

No.     Time        Source                Destination           Protocol Info
61 1.416360
Frame
0000 00 04 e2 22 ..."Z.... l...E.
...
Reassembled
0000 48 54 54 2c HTTP/1.1 200 OK.

Yo can try with:
Code:
Vstr:~$ X=$(awk '/^No/{print;exit}' input)
sed -e "/$X/,/Reassembled/d;s/^$/$X/" input
No.     Time        Source                Destination           Protocol Info
0000 48 4f 4b 0d HTTP/1.1 200 OK.
0010 0a 30 20 4e .Date: Sat, 20 N
No.     Time        Source                Destination           Protocol Info
0000 48 54 54 2c HTTP/1.1 200 OK.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk to remove specific column to one range

I need to remove specific column to one range source file 3 1 000123456 2 2 000123569 3 3 000123564 12 000123156 15 000125648 128 000125648 Output required 3 000123456 2 000123569 3 000123564 12 000123156 15 000125648 128 000125648 (6 Replies)
Discussion started by: ranjancom2000
6 Replies

2. Shell Programming and Scripting

Remove line break at specific position

Hi, I need to remove line breaks from a file, but only the ones at specific position. Input file: this is ok this line is divided at posit ion 30. The same as this one, also position 30 the rest of lines are ok with different lengths The longest ones are always s plitted at same... (15 Replies)
Discussion started by: qranumo
15 Replies

3. UNIX for Advanced & Expert Users

Vi remove line range containing a string

In vi I would like to remove a line containing a string. I thought after reading this I could do this. https://www.unix.com/302297288-post3.html :'3560,3572/gcc/d' It keeps complaining vi mark not set. And sometimes it complains E488: Trailing characters. I don't understand what mark... (5 Replies)
Discussion started by: cokedude
5 Replies

4. Shell Programming and Scripting

Remove every line with specific string, and also the one above and below it

I would like to identify every line with a specific string, in this case: "Mamma". I would like to remove that line, and also the line above it and below it. So the below Where are all amazing Flats Look At The Great Big White Hey There Hot Mamma You Are So hot Baby I wish You were Mine... (5 Replies)
Discussion started by: phpchick
5 Replies

5. Shell Programming and Scripting

Remove line with specific character

HI Input :- Aog:0rt__dev_8 LAAXU24 vs.3 LAA40l0 ** LAAXU241 ** Output :- Aog:0rt__dev_8 LAAXU24 vs.3 Delete the line with ** (3 Replies)
Discussion started by: pareshkp
3 Replies

6. Shell Programming and Scripting

Remove only specific char on every line when exists

Hi I need to remove "|" char when it's the last char of the line. Input file: generoso|desprendido|altruista| abnegar|ceder|sacrificar| abocetado-da|esbozado| apuntado|insinuado|incompleto abocetar|esbozar|bosquejar| diseņar|delinear ------------------------ output need --- ... (11 Replies)
Discussion started by: lookoo
11 Replies

7. Shell Programming and Scripting

How to remove unwanted elements from the command line?

CREATE TYPE "SUPERB"."OE_L2_FOOTERDATA_REC" OID '1232323232' IS OBJECT ( AWLSTrxId NUMBER, AdjPurchaseAmount NUMBER, Network NUMBER, ConfigVersion NUMBER ); / I wanted my output to be as follow: CREATE TYPE OE_L2_FOOTERDATA_REC OID '1232323232'... (7 Replies)
Discussion started by: jediwannabe
7 Replies

8. Shell Programming and Scripting

Remove a specific line from grep output string

Dear All I want to search string "1000" from input file and if it found i want remove line that contain 1000 and also remove 3 line above it and 2 line below it. INPUT FILE: BHAT-D 2 aaa ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES 50 ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

9. Shell Programming and Scripting

remove a specific line in a LARGE file

Hi guys, i have a really big file, and i want to remove a specific line. sed -i '5d' fileThis doesn't really work, it takes a lot of time... The whole script is supposed to remove every word containing less than 5 characters and currently looks like this: #!/bin/bash line="1"... (2 Replies)
Discussion started by: blubbiblubbkekz
2 Replies

10. Shell Programming and Scripting

Remove Line that contains specific string

I am looking for a way to remove any line in a text file that contains the string "Mac address". I guess you would grep and sed, but I am not sure how to do this. Thanks for you help. (3 Replies)
Discussion started by: CBarraford
3 Replies
Login or Register to Ask a Question