The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting only directory not files manoj.solaris Linux 13 05-02-2008 05:24 AM
deleting lines from multiple text files vrms Shell Programming and Scripting 3 04-25-2008 08:01 AM
Deleting Lines from .CSV Files 009satya Shell Programming and Scripting 1 11-13-2006 12:30 PM
Deleting specific lines in a file ramu_1980 Shell Programming and Scripting 4 02-15-2005 10:41 AM
Deleting specific files greater then 90 days beilstwh Shell Programming and Scripting 2 07-22-2004 12:27 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-25-2008
Registered User
 

Join Date: Apr 2008
Posts: 16
deleting specific lines from all files in a directory

I have a directory full of text data files.

Unfortunately I need to get rid of the 7th and 8th line from them all so that I can input them into a GIS application.

I've used an awk script to do one at a time but due to the sheer number of files I need some kind of loop mechanism to automate it.

The awk script used: -
awk 'BEGIN{getline f;getline t}FNR==f,FNR==t{next}1' numbers.txt inputfile > outputfile

where numbers.txt is merely a document with the numbers 7 and 8

My guess is that I need a way of piping the output from ls (of the directory) into where the inputfile is situated and a counter to loop through till the end.

Any suggestions will be welcome (an awk suggestion would be preferable to pearl)

Thanks all
Reply With Quote
Forum Sponsor
  #2  
Old 04-25-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
for f in *; do
  awk 'NR!=7 && NR!=8' "$f" >"$f.tmp"
  mv "$f.tmp" "$f"
done
It would actually be easier in sed, but if you have weird hangups about anything which isn't awk ...

ls has no particular use here; it's the shell which expands wildcards, not ls.
Reply With Quote
  #3  
Old 04-25-2008
Registered User
 

Join Date: Apr 2008
Posts: 16
worked a charm

Thanks esa

cheers
Reply With Quote
  #4  
Old 04-25-2008
Registered User
 

Join Date: Apr 2008
Posts: 16
oops sorry

era I mean

cheers
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:36 AM.


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

Content Relevant URLs by vBSEO 3.2.0