How to delete all lines before a specific word? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to delete all lines before a specific word?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-23-2010
hakermania hakermania is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 22 September 2013, 7:10 AM EDT
Posts: 169
Thanks: 34
Thanked 4 Times in 4 Posts
How to delete all lines before a specific word?

Let's say we have a file containing:

Code:
alllllsadfsdasdf
qwdDDDaassss
ccxxcxc#2222
dssSSSSddDDDD
D1Sqn2NYOHgTI
Hello
Alex
ssS@3

Ok, and let's say we want to delete all words from D1Sqn2NYOHgTI and back, this means
to delete the words (and the lines of them) :

Code:
alllllsadfsdasdf
qwdDDDaassss
ccxxcxc#2222
dssSSSSddDDDD
D1Sqn2NYOHgTI

Can this be done? I need actually a command to delete the words before the D1Sqn2NYOHgTI (and itself), because I know the command which deletes empty lines...
Sponsored Links
    #2  
Old 07-23-2010
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 18 April 2014, 10:05 AM EDT
Location: The Netherlands
Posts: 7,667
Thanks: 116
Thanked 525 Times in 496 Posts

Code:
sed '1,/D1S/d' file

or:

Code:
awk 'f;/D1S/{f=1}' file

Sponsored Links
    #3  
Old 07-23-2010
hakermania hakermania is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 22 September 2013, 7:10 AM EDT
Posts: 169
Thanks: 34
Thanked 4 Times in 4 Posts
thx!!!
Sponsored Links
Closed 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
search a word and delete consecutive lines below it vikas027 Shell Programming and Scripting 3 06-03-2009 02:02 AM
Delete specific lines from a file itzz.me Shell Programming and Scripting 4 04-08-2009 04:12 PM
delete lines containing a specific word in afile sireesha9 Shell Programming and Scripting 4 02-23-2009 05:07 AM
How to delete specific lines at the same time zanetti321 UNIX for Advanced & Expert Users 1 03-24-2008 07:00 AM
Delete specific lines in a text file dniz Programming 9 08-08-2005 08:30 AM



All times are GMT -4. The time now is 07:43 PM.