Created
April 23, 2012 09:33
-
-
Save dueyfinster/2469815 to your computer and use it in GitHub Desktop.
Script to output last 30% of file by lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/bin/sh | |
# Public Domain, by Neil Grogan 2010 | |
# Script to output last 30% of file by lines | |
OLDFILE="oldlog.txt" | |
NEWFILE="newlog.txt" | |
PERCENT=0.7 | |
#Use wc to count lines | |
LINES=$(wc -l $OLDFILE | awk '{ print $1}') | |
#Linespercent = 2 decimal places, lines by percent, round to whole | |
LINESPERCENT=$(echo "scale=2; $LINES*$PERCENT" | bc | xargs printf "%1.0f" ) | |
# Use tail to get last 30% and output, can use tail -s with sleep time to have it run on sched. | |
tail -n $LINESPERCENT $OLDFILE > $NEWFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment