Removing a bunch of lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing a bunch of lines
# 1  
Old 10-21-2010
Removing a bunch of lines

I have a file that contains the following multiple times:

Code:
0<<
bla bla bla
bla bla bla
exit;

Can somebody give me a sed or AWK command I can use to remove all
occurances from this file.

I would like it to find 0<< (note the zero may be proceeded by spaces) and remove that line and the other 3 lines directly under it.

Thanks in advance to all who answer.

Last edited by vgersh99; 10-21-2010 at 11:50 AM.. Reason: code tags, please!
# 2  
Old 10-21-2010
Code:
nawk '/^ *0<</ {n=5}; n && --n{next}1' myFile

# 3  
Old 10-21-2010
Quote:
Originally Posted by vgersh99
Code:
nawk '/^ *0<</ {n=5}; n && --n{next}1' myFile

Thanks for the help. Just curious, why nawk and not awk is this statement not portable amongst different flavors of UNIX (ie Solaris, AIX, HPUX).

I also like to know if I got understand your code. I get the matching part.
The second part, is because I have four lines to delete you set your varable n=5, decrement it and delete a line at a time?

Very eloquant solutuon.
# 4  
Old 10-21-2010
Quote:
Originally Posted by BeefStu
Thanks for the help. Just curious, why nawk and not awk is this statement not portable amongst different flavors of UNIX (ie Solaris, AIX, HPUX).
Solaris' /bin/awk is old and broken. Use either /bin/nawk or /usr/xpg4/bin/awk on Solaris.
On most/some of the other OSs, 'awk' is linked symbolcally to 'nawk'
Quote:
Originally Posted by BeefStu
I also like to know if I got understand your code. I get the matching part.
The second part, is because I have four lines to delete you set your varable n=5, decrement it and delete a line at a time?
Once the 'match' is found, we 'skip' (next) the number of lines (initialized at the finding of the match to 5).
When 'n!=0' (all to be skipped lines have been skipped), we print lines 'as is' - '1' is the equivalent of '{print $0}'.
Quote:
Originally Posted by BeefStu
Very eloquant solutuon.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I need help to removing repetitive lines

Hello SuperUsers! First i wanna say my english sucks.. Don't hate me for that. :rolleyes: I need to make a Bash for removing smilar lines from an output file. My output file always same. Line 1 & 2 Stays. And others similar to this lines needs to be delete. </UsageData><?xml version="1.0"... (4 Replies)
Discussion started by: morphin
4 Replies

2. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

3. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

4. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

5. Shell Programming and Scripting

Removing Lines that Contain a Certain String

I'm writing a UNIX script to interpret text files and search for certain strings to output and need to delete certain lines that contain characters that I would like removed from the file. The rest of the script is already completed and I have it output how I would like, but I cannot seem to get... (2 Replies)
Discussion started by: DetroitLolcat
2 Replies

6. Shell Programming and Scripting

removing lines without text

How do I remove line that do not contain text, but that do contain tabs? I have tried the command cat file | awk NF but that doesn't work when the lines contain tabs (and spaces). I have also tried: cat file | sed '/^$/d' (9 Replies)
Discussion started by: locoroco
9 Replies

7. Shell Programming and Scripting

Removing last two lines

I have an awk script that replaces ">" with % %> %< SOURCE", ++i %( PHASE 1", i I use the following script />/ { if ( FNR > 1 ) { print "%)" print "%>" } print "" print "%< SOURCE", ++i (11 Replies)
Discussion started by: kristinu
11 Replies

8. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

9. Shell Programming and Scripting

Removing lines having #

I have a script which goes to different directories and gives the values of all the input parameters, Something as follows cd /opt grep script-filter = yes *.conf grep user-and-group-in-same-suffix = yes *.conf grep worker-threads = 300 *.conf grep failover-auth = *.conf grep... (9 Replies)
Discussion started by: openspark
9 Replies

10. Shell Programming and Scripting

Removing lines from a file

Hello i have 2 files file1 and file2 as shown below file1 110010000000206|567810008161509 110010000000207|567810072227627 110010000000208|567811368851555 110010000000209|567811422513652 110010000000210|567812130217683 110010000000211|567813220211182 110010000000212|567813449322589... (4 Replies)
Discussion started by: PradeepRed
4 Replies
Login or Register to Ask a Question