For deleting a line from a file without open the file you can use sed.
For example, it has been very useful many times for me after anoying messages from ssh when a host I use to connect change the IP...
And sometimes you don't know the line number but you know a specific word from this line.
- # 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
CommentsSubscribe to comments
You need to login to post a comment.