Tip: Add a prefix/suffix to each line of a file

Pretty neat tip, I needed to add a prefix of ‘ufw deny from’ to a list of IP addresses in a file, you can do it easily with awk, using this:

~

Pretty neat tip, I needed to add a prefix of ‘ufw deny from’ to a list of IP addresses in a file, you can do it easily with awk, using this:

awk '$0="ufw deny from "$0' original.list > updated.list

And your updated.list file will now have each line prefixed. You can move the string around to get a suffix too.


~

Comments