Visit The New, Modern Unix Linux Community

Delete all CONSECUTIVE text lines from file shell scripting

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete all CONSECUTIVE text lines from file shell scripting
# 1  
Oracle Delete all CONSECUTIVE text lines from file shell scripting


I have a text file like below. THe content of the text will vary.

Entire text file have four consecutive lines followed with blank line.

I want to delete the occurrence of the two consicutive lines in the text file. I don't have pattern to match and delete. Just i need to delete all two lines in the text file.




Moderator's Comments:
Mod Comment Use code tags, thanks.
# 2  
Any attempts/ideas/thoughts from your side?
# 3  
No ... After searching i didnt get any idea anywhere.
# 4  
I was more talking of your own efforts... anyhow, try
awk '/^ *$/ {CNT = 0; print; next} ++CNT < 3 {T[CNT] = $0; next} CNT == 3 {print T[1]; print T[2]} 1' file

This User Gave Thanks to RudiC For This Post:
# 5  
Thanks Much it is working fine and suits my requirement
# 6  
awk 'NF>2' RS="\n\n" ORS="\n\n" infile

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #818
Difficulty: Medium
In CSS, E > F matches an F element child of an E element.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

2. Shell Programming and Scripting

How to get the consecutive last 10 week day date using UNIX ksh shell scripting?

Hi, i am writing a ksh shell script to check the last month end date whether it is falling in last 10 week day date, I am not sure How to use "Mr. Perderabo's date calculator", Could you Please let me know how to use to get my requirement, I tried my own script but duplicate week day and... (5 Replies)
Discussion started by: karthikram
5 Replies

3. UNIX for Dummies Questions & Answers

Delete 26 consecutive lines in a file

I have a text file that is about 90,000 lines long. How would I delete lines 64-89, 152-177, 240-265, 328-353... etc? The sections I would like to delete are 26 lines long and the number of lines between the sections I would like to delete is 62 lines. Thanks very much in advance. (6 Replies)
Discussion started by: MDeBiasse
6 Replies

4. Shell Programming and Scripting

How to delete lines of a text file based on another text file?

I have 2 TXT files with with 8 columns in them(tab separated). First file has 2000 entries whereas 2nd file has 300 entries. The first file has ALL the lines of second file. Now I need to remove those 300 lines (which are in both files) from first file so that first file's line count become... (2 Replies)
Discussion started by: prvnrk
2 Replies

5. Shell Programming and Scripting

How to delete lines from text file?

hi guys, I have very large txt files (200GB) and just want to to delete the first two lines (headers). So far I used sed -i '1,2d' infile.txtbut this command always takes extremely long as it writes all again. Is there a better way to do it (ie just to delete the lines without writing all... (2 Replies)
Discussion started by: TuAd
2 Replies

6. Shell Programming and Scripting

how to delete two consecutive lines from the file

Hi guys I am deleting a unique line from the file and also need to remove the line above it which is NOT unique and servers as a record separator. Here is an example: # 101 803E 823F 8240 # 102 755f 4F2A 4F2B # 290 747D 0926 0927 # 999 8123 813E ... (5 Replies)
Discussion started by: aoussenko
5 Replies

7. Shell Programming and Scripting

looking for a script that will delete lines in a text file

it will grep for a line and then delete these line. how do i begin to write this script if theres no available one? (3 Replies)
Discussion started by: garfish
3 Replies

8. Shell Programming and Scripting

look for two consecutive lines in all text files

How to get (a list of) all the text files in the current directory and subdirectories which has the following two consecutive lines: ctrl_end_date=2009 ctrl_process=EXPIRED OR ctrl_end_date=2010 ctrl_process=EXPIRED i.e. (ctrl_end_date=2009 OR ctrl_end_date=2010) AND ctrl_process=EXPIRED... (6 Replies)
Discussion started by: albertkao
6 Replies

9. UNIX for Dummies Questions & Answers

Delete vertical lines in an text file

Hi everybody! I need to delete several vertical lines in a huge text file. It should work like the example below. Delete the vertical lines 2 and 8. 123456789 masldfjla afsajfwel sajfljsaf safsarfrl sajfeljwq 1345679 msldfja asajfwl sjfljsf sfsarfl sjfeljq Is there a... (11 Replies)
Discussion started by: relaxo
11 Replies

10. Shell Programming and Scripting

search a word and delete consecutive lines below it

Hi all coders, I need a help to process some data. I have this file, 3 09/21/08 03:32:07 started undef mino Oracle m Message Text : The Oracle session with the PID 1103 has a CPU time consuming of 999.00... (3 Replies)
Discussion started by: vikas027
3 Replies

Featured Tech Videos