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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 07-23-2010
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 27 March 2015, 3:12 PM EDT
Location: The Netherlands
Posts: 7,730
Thanks: 128
Thanked 544 Times in 512 Posts

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

or:

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

Sponsored Links
    #3  
Old Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 08:16 AM.