How to modify the content of a specific line in shell?

To edit the content of a specific line, you can use the sed command. For example, to modify the content of the 5th line, you can use the following command:

sed -i '5s/.*/new content/' file.txt

This command will replace the content of the 5th line in the file file.txt with “new content”. You can replace 5 with any line number you want to modify.

bannerAds