The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 11:08 AM
Deleting last 2 lines from the file. videsh77 Shell Programming and Scripting 4 04-06-2007 01:14 PM
Deleting Lines from .csv file 009satya Shell Programming and Scripting 3 11-14-2006 03:41 AM
deleting lines in a log file BG_JrAdmin Shell Programming and Scripting 2 08-22-2006 11:12 AM
Deleting specific columns from a file premar Shell Programming and Scripting 11 02-14-2006 07:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-13-2005
ramu_1980 ramu_1980 is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 3
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
  #2 (permalink)  
Old 02-13-2005
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,661
Why, may I ask? Is this homework?

Neo
  #3 (permalink)  
Old 02-13-2005
ramu_1980 ramu_1980 is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 3
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
  #4 (permalink)  
Old 02-15-2005
ramu_1980 ramu_1980 is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 3
Does anyone have a script or a way to do this???
  #5 (permalink)  
Old 02-15-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0