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
Search a list of lines in file into files sriram003 UNIX for Advanced & Expert Users 2 05-20-2008 04:23 AM
deleting specific lines from all files in a directory vrms UNIX for Dummies Questions & Answers 3 04-25-2008 08:08 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 11:30 AM
PHP Outputting finite amount of lines from a file pondlife Shell Programming and Scripting 1 10-26-2005 08:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-14-2006
Registered User
 

Join Date: Apr 2006
Posts: 3
Stumble this Post!
deleting a varying amount of lines from a list of files

I did search the posts for info on this and while there were some in the ballpark, none addressed this specifically. (also I tried to post this once it said I was logged out, so hopefully I'm not sending a duplicate here).

I have a set of files (250 +/-) where I need to delete the first "$x" number of lines and output what remains to a new file (or cat all the results into one file)

so far, I was able to piece together this much:

cat -n index20a6.html index3e43.html index6a84.html (...and so on) | grep
'<TITLE>Section 440.' | awk '{print $1}'

it results in this:

973
1722
2219
...

'<TITLE>Section 440.' is on a different line in each file so the amount of line to delete will vary.

The missing piece is to delete '1,973d' '1,1722d' '1,2219d' as it goes through and create a new file.

(also if I can go through this list recursively rather than list all the files in my command, that would be a bonus!)

Thanks for any assitance on this!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-14-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
Try:
Code:
#! /usr/bin/ksh
cd /the/directory
exec > onebigoutputfile
find . -name index\*.html | while read fname ; do
           sed '1,/<TITLE> Section 440./d' < $fname
done
exit 0
Reply With Quote
  #3 (permalink)  
Old 04-14-2006
Registered User
 

Join Date: Apr 2006
Posts: 3
Stumble this Post!
First, Thanks for the reply!

That results in just a list of the filenames showing in "onebigoutputfile"

./index018e.html
./index0271.html
./index031c.html
./index03bb.html
./index03fe.html
./index04b3.html
...

I'll continue to work with it.
Reply With Quote
  #4 (permalink)  
Old 04-14-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
Retested....
Code:
$ cat script
#! /usr/bin/ksh
#cd /the/directory
#exec > onebigoutputfile
find . -name index\*.html | while read fname ; do
           sed '1,/<TITLE> Section 440./d' < $fname
done
exit 0
$
$
$
$ cat index1.html
hhhh
kkkkk
hhhh <TITLE> Section 440.
jjjjj 5
jjjjjj8
jjjj6
iiii9
$
$
$
$
$
$ ./script
jjjjj 5
jjjjjj8
jjjj6
iiii9
$
I commented out the cd and the exec for easy testing. The only way your result makes sense is if each of your files contains a single line after the "seection 440" line and that single line is only the file name. I assume you can cut and paste accurately, so then it beats me...
Reply With Quote
  #5 (permalink)  
Old 04-14-2006
Registered User
 

Join Date: Apr 2006
Posts: 3
Stumble this Post!
I rechecked and the original cut and paste was directly from what I was running earlier. Of course, I'm no pro when it comes to working in the Shell, so I'll just have to keep working with what you posted and see where I'm going astray.

Thank you for taking the time to help with this.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:36 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