DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Print Some Lines of a File with Head and Tail


$ echo "1\n2\n3\n4\n5\n6" > test

$ cat test 
1
2
3
4
5
6

$ tail -n+2 test   // remove head (start from 2nd line)
2
3
4
5
6

$ head -n-2 test   // remove tail (discard last 2 lines)
1
2
3
4

$ head -2 test     // only head
1
2

$ tail -2 test     // only tail
5
6


Published

Mar 7, 2016

Last Updated

Mar 7, 2016

Category

Tech

Tags

  • head 1
  • shell 46
  • tail 1

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor