# Using head - Print few lines (5 lines) from the top of a file head -n 5 file.txt # Using tail - Print few lines (5 lines) from the bottom of a file tail -n 5 file.txt # Using sed # show from line 12 to line 23 sed -n '12,23 p' archivo.txt # or just one (line 15) sed -n 15p archivo.txt
# delete the line 18 from '~/.ssh/known_hosts' file sed -i '18 d' ~/.ssh/known_hosts # also sed -i 18d ~/.ssh/known_hosts # delete few lines # delete 6 lines from line 8 sed -i 8,+6d file.txt # delete the line where is 'TO DELETE' sed -i '/TO DELETE/ d' file.txt
$cat testfile 123654 asdfasf 46546 asfasd 23456 abcd 54646 need to print 465465 need tp print 654654 need to print 65465 need to print 23456 abcd 654654 asdfasfuoe sed -n '/abcd/,/abcd/p' testfile | grep -v abcd 54646 need to print 465465 need tp print 654654 need to print 65465 need to print