August 25th, 2003, 03:21 PM
remove contents of a file
Can someone show how to remove the content of a file leaving the last 100 lines? The aim is to preserve the perimission for the file. Thanks.
August 26th, 2003, 09:43 AM
Well, if it were me, I'd tail out the lines to a temp file, then zero out the original, and cat the temp contents back into the original, i.e.:
tail -100 > $TEMPFILE
cat /dev/null > $FILE1
cat $TEMPFILE >> $FILE1
That should do it and keep the permissions set, since you're not deleting the file, just modifying it's contents. If you need any different number of lines, not 100, you can just substitute the number in the tail line above.
I'm sure there's another cleaner way to do this, but the above should be a workable hack.