Mark Post wrote:
On Tue, Sep 4, 2007 at  2:21 PM, in message
<[EMAIL PROTECTED]>, "Scully, William P"
<[EMAIL PROTECTED]> wrote:
What's the best technique for trimming a file?  IE: I have file
"/var/log/toolarge".  What's the fastest technique to discard

- The first 10,000 records?
sed -i -e '1,10000 d' /var/log/toolarge

- The last 10,000 records?
count=$(wc -l /var/log/toolarge | cut -f1 -d" ")

Why is the cut useful?

let start=$count-9999
if [ ${start} -le 1 ]; then
   echo start is set to 1
   let start=1
fi
sed -i -e "$start,$ d" /var/log/toolarge

Do we want to read the file twice?

Here's a sed line that I picked up someplace (I think there's a site
devoted to sed) and adapted, but don't really understand, It prints a
few, then maintains a hold buffer to the end, and then prints the hold
buffer.

Perhaps it too can be adapted, and do it in one pass.

CPU consumption may be a drawback though.


And as a bonus, since files are stream oriented, what's the fastest
technique for finding out how many records are in the file?

wc -l /var/log/toolarge



--

Cheers
John

-- spambait
[EMAIL PROTECTED]  [EMAIL PROTECTED]

Please do not reply off-list

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390

Reply via email to