Say I have a file named output.txt. Every line in output.txt starts with a different word. How could I perform something like if any line starts with "word" then add "new word" to the end of the line?
4 Answers
Andy's answer is good. If you want to use sed you could do
sed 's/\(^word.*$\)/\1new word/' input.txt > output.txt
1 Comment
chepner
Even simpler:
sed '/^word/s/$/new word/' input.txt > output.txt. This "replaces" the end of the line with "new word", but only on lines that begin with "word".