Skip to content

Instantly share code, notes, and snippets.

@mkoura
Last active April 2, 2016 09:33
Show Gist options
  • Save mkoura/757ba441b09fd6ac59376c155c40a738 to your computer and use it in GitHub Desktop.
Save mkoura/757ba441b09fd6ac59376c155c40a738 to your computer and use it in GitHub Desktop.
shell interview problems
# 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