Prepend ## to every line in a text file

Solution 1:

You can use sed to do that:

sed -i.bak 's/^/##/' file

This replaces the start of the line (^) with ##.

With the -i.bak switch, sed edits the file in-place, but creates a backup copy with extension.bak.

Solution 2:

Here is a solution to this problem using perl

perl -e 'while (<>) {print "##$_"}' < infile > outfile