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 > 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 08:24 AM
deleting lines from multiple text files vrms Shell Programming and Scripting 3 04-25-2008 11:01 AM
Deleting Lines from .CSV Files 009satya Shell Programming and Scripting 1 11-13-2006 03:30 PM
Deleting specific lines in a file ramu_1980 Shell Programming and Scripting 4 02-15-2005 01:41 PM
Deleting specific files greater then 90 days beilstwh Shell Programming and Scripting 2 07-22-2004 03:27 PM

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 04-25-2008
vrms vrms is offline
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
  #2 (permalink)  
Old 04-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
  #3 (permalink)  
Old 04-25-2008
vrms vrms is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 16
worked a charm

Thanks esa

cheers
  #4 (permalink)  
Old 04-25-2008
vrms vrms is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 16
oops sorry

era I mean

cheers
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:59 PM.


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