Quickzi: How To Replace a Line in a Text File
Here is a quick tip on how to use sed to replace a line in a text file from the command line, without opening it.
Replace a Line in a File
First, replace the text you want with sed and output it into a temporary file to ensure that it is correct:
# sed -e 's/original-text/new-text/' textFile > newFile
View the newFile and make sure that the line is correctly replaced:
# more newFile
Overwrite the textFile with the newFile:
# mv newFile textFile
Popularity: 3% [?]
Tagged with: Linux • quickzi • tips
Filed under: Linux
Like this post? Subscribe to my RSS feed and get loads more!













Leave a Reply