Skip to content

Instantly share code, notes, and snippets.

@maycat
Created November 22, 2013 02:38
Show Gist options
  • Save maycat/7593877 to your computer and use it in GitHub Desktop.
Save maycat/7593877 to your computer and use it in GitHub Desktop.
sed cookbook
# print the first line
sed -n 1p somefile.txt
sed '1!d' somefile.txt
# print lines 2 to 4
sed -n 2,4p somefile.txt
sed '2,4!d' somefile.txt
# print lines 1 to 2 and line 4
sed -n -e 1,2p -e 4p somefile.txt
# References
#
# 1. http://linuxcommando.blogspot.kr/2008/03/using-sed-to-extract-lines-in-text-file.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment