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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-14-2006
benair benair is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 3
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!
  #2 (permalink)  
Old 04-14-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,123
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
  #3 (permalink)  
Old 04-14-2006
benair benair is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 3
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.
  #4 (permalink)  
Old 04-14-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,123
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...
  #5 (permalink)  
Old 04-14-2006
benair benair is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 3
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.
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 03:08 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