The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting specific lines from all files in a directory vrms UNIX for Dummies Questions & Answers 3 04-25-2008 08:08 AM
Deleting last 2 lines from the file. videsh77 Shell Programming and Scripting 4 04-06-2007 10:14 AM
Deleting Lines from .csv file 009satya Shell Programming and Scripting 3 11-13-2006 11:41 PM
deleting lines in a log file BG_JrAdmin Shell Programming and Scripting 2 08-22-2006 08:12 AM
Deleting specific columns from a file premar Shell Programming and Scripting 11 02-14-2006 03:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-13-2005
Registered User
 

Join Date: Feb 2005
Posts: 3
Stumble this Post!
Deleting specific lines in a file

I have a file which has some lines starting with a particular word. I would like to delete 5 lines before each such line containing that particular word.

eg:
line1
line2
line3
line4
line5
line6
"particular word"...

I would like to delete line2-line6 and all such occurences in that file.

Thanks,
Ramu
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-13-2005
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,289
Stumble this Post!
Why, may I ask? Is this homework?

Neo
Reply With Quote
  #3 (permalink)  
Old 02-13-2005
Registered User
 

Join Date: Feb 2005
Posts: 3
Stumble this Post!
Nope.. I was talking to friend and he needed something like that at work. I was trying to find some solution on net and found this group.

I am just trying to learn more about shell scripting.

Ramu
Reply With Quote
  #4 (permalink)  
Old 02-15-2005
Registered User
 

Join Date: Feb 2005
Posts: 3
Stumble this Post!
Does anyone have a script or a way to do this???
Reply With Quote
  #5 (permalink)  
Old 02-15-2005
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
Stumble this Post!
some thing like ...
Not tested for all inputs ...
May have to tweak depend on input you give in $1.

Code:
a=`grep -n "$1" file1 | cut -d":" -f 1`
((a=a-1))
((b=a-4))
sed ""$b","$a" d" file1
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0