Last active
April 2, 2016 09:33
-
-
Save mkoura/757ba441b09fd6ac59376c155c40a738 to your computer and use it in GitHub Desktop.
shell interview problems
This file contains hidden or 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
# from a file print 10 lines that are directly before the last ten lines without using tail or head | |
{ tac | while read l; do [ "${i:=0}" -lt 20 -a "$i" -ge 10 ] && echo "$l"; i=$(($i + 1)); done | tac; } < file | |
# monitor changes to a file without using tail -f | |
while : ; do read line && echo "$line" || sleep 1; done < file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment