![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| parsing xml with awk/sed | ricgamch | Shell Programming and Scripting | 3 | 05-28-2008 11:39 AM |
| Parsing Files | almeidamik | Shell Programming and Scripting | 4 | 04-13-2008 11:46 AM |
| parsing | tungaw2004 | UNIX for Dummies Questions & Answers | 15 | 03-27-2007 09:33 PM |
| parsing xml | walnut | Shell Programming and Scripting | 1 | 02-21-2006 05:32 AM |
| XML parsing | handak9 | High Level Programming | 1 | 11-01-2004 08:13 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
parsing files
I have a large file that needs to be weeded through every month.
The file has events that go back forever, but on a monthly basis I need to look thru the last months worth of data. Is there a best way to get the script to know where it left off last time it read the file, like maybe putting a special couple characters in the file each time it reads it at the end where it left off? |
|
||||
|
1. If you have a neverending accumulating file, you have a disk space problem waiting to happen. Consider: do file rotation. Create a new file for each month, at the end of the month append the monthly stuff to the giant file. This way you don't get loss of data, or problems with strange errors in the app(s) that write to the file. 2. If business reasons dictate another approach, use the last line number you read from the file the previous month. Store it in a file. For monthly processing, read the file for where to start then update the the linecount file with where you left off. If you chop off this motnh's stuff and store it in a much smaller file, any grep or sed, etc. operation will be infinitely faster. Code:
#!/bin/ksh last_line=`cat ./linecountfile` sed -n "$last_line,$p" giantfile > workingfile #........ play around with working file. #........ grep, sed etc. # done playing linecount=`sed -n '$=' workingfile` echo "`$last_line + $linecount | bc`" > ./linecountfile I don't know if giantfile is a "largefile", > 2.4GB, so I used bc to do the addition. Last edited by jim mcnamara; 08-23-2006 at 12:48 PM.. |
![]() |
| Bookmarks |
| Tags |
| grep or |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|