Home
Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Delete all CONSECUTIVE text lines from file shell scripting

Tags
delete, lines in file, sed, shell bash ksh, shell scripts, solved

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 07-20-2016
Oracle Delete all CONSECUTIVE text lines from file shell scripting

Hi

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.

Code:
a
a
a
a
 
a
a

a
a
a
a

a
a
a
a


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

The Following User Says Thank You to RudiC For This Useful Post:
RJSKR28 (07-20-2016)
# 5  
Old 07-20-2016
Thanks Much it is working fine and suits my requirement
# 6  
Old 07-21-2016
Code:
awk 'NF>2' RS="\n\n" ORS="\n\n" infile

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Tried many options but unable to delete blank lines from text file uuuunnnn Shell Programming and Scripting 9 07-24-2017 08:49 PM
Deleting specific lines from text file via scripting Gautham Shell Programming and Scripting 8 04-17-2014 07:42 AM
Shell script to read lines in a text file and filter user data Shell Programming and Scripting VikrantD UNIX for Dummies Questions & Answers 3 03-25-2014 04:28 AM
How to get the consecutive last 10 week day date using UNIX ksh shell scripting? karthikram Shell Programming and Scripting 5 01-01-2014 04:07 AM
Delete 26 consecutive lines in a file MDeBiasse UNIX for Dummies Questions & Answers 6 05-24-2013 12:57 AM
How to delete lines of a text file based on another text file? prvnrk Shell Programming and Scripting 2 03-07-2013 10:35 PM
Delete a record in a xml file using shell scripting sdesstp UNIX for Dummies Questions & Answers 4 06-21-2012 06:52 AM
How to delete lines from text file? TuAd Shell Programming and Scripting 2 07-26-2011 12:30 PM
how to delete two consecutive lines from the file aoussenko Shell Programming and Scripting 5 04-12-2011 03:34 PM
looking for a script that will delete lines in a text file garfish Shell Programming and Scripting 3 11-05-2010 06:43 AM
look for two consecutive lines in all text files albertkao Shell Programming and Scripting 6 09-03-2010 01:08 AM
Delete vertical lines in an text file relaxo UNIX for Dummies Questions & Answers 11 03-03-2010 06:53 AM
search a word and delete consecutive lines below it vikas027 Shell Programming and Scripting 3 06-03-2009 03:02 AM
Delete blocks of lines from text file nrbhole Shell Programming and Scripting 4 12-19-2007 06:17 AM
Delete specific lines in a text file dniz Programming 9 08-08-2005 09:30 AM


All times are GMT -4. The time now is 08:30 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password