nixcraft recommended awk and sed, which are both clean and accurate. However, I am not sure if you meant to say that you wanted to append something to âevery lineâ in the existing text file? If so, then I would use sed (stream editor) to get there:
root# echo "this is a line" > my.txt
root# cat my.txt
this is a line
root# cat my.txt | sed 's/$/ \*NEWTEXT\*/' > mynewfile.txt
root# cat mynewfile.txt
this is a line *NEWTEXT*
root#
Tools like grep, sed and awk can also pattern match, and swap in/out information easily.
One of my favorite actions is to strip out blank lines and comments from configuration files, so I can see whatâs active.
cat config.txt | grep -v ^$ |grep -v "^#" | more
The first grep âignoresâ blank lines, while the second ignores leading # symbols.
If you wanted to convert empty lines to comment markers, then sed would be great at that:
cat config.txt | sed 's/^$/# /' > revised_config.txt