Skip to content

Instantly share code, notes, and snippets.

@WoodProgrammer
Created August 2, 2017 17:22
Show Gist options
  • Select an option

  • Save WoodProgrammer/dcbb2fc675187272046f19e3777a708c to your computer and use it in GitHub Desktop.

Select an option

Save WoodProgrammer/dcbb2fc675187272046f19e3777a708c to your computer and use it in GitHub Desktop.
##### HEAD_COMMAND
#!/bin/bash
x=$1
i=0
while read line
do
echo $line
((i++))
if [ $i -gt $x ]
then
exit
fi
done < test.log
########Tail_COmmand
#!/bin/bash
word_count=$(wc -l test.log |awk '{print $1}')
line_count=$2
stop_word=$[ $word_count - $line_count ]
i=0
junk=0
while read line
do
if [ $i -le $stop_word ]
then
junk=$[junk+1]
else
echo $line
fi
i=$[i+1]
done < test.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment