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 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

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 08-23-2006
BG_JrAdmin BG_JrAdmin is online now
Registered User
  
 

Join Date: Feb 2005
Posts: 142
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?
  #2 (permalink)  
Old 08-23-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,811
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..
Closed Thread

Bookmarks

Tags
grep or

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 11:35 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