Skip to content

Instantly share code, notes, and snippets.

@selfawaresoup
Last active December 19, 2015 03:49
Show Gist options
  • Save selfawaresoup/5892744 to your computer and use it in GitHub Desktop.
Save selfawaresoup/5892744 to your computer and use it in GitHub Desktop.
Text operations in shell scripts

Extract one specific line with AWK

  • awk 'NR==40550{print;exit}' <file>

Extract line 40550 to 40601:

  • sed '40602q;40550,40601!d' <file>
  • awk 'NR==40550,NR==40601' <file>

Extract line 60451 and 68451:

  • sed -n '68452q;60451p;68451p' <file>
  • awk 'FNR==60451 || FNR==68451 {print}; FNR==68452 {exit}' <file> Much faster than sed!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment