Prepend ## to every line in a text file
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
.
Here is a solution to this problem using perl
perl -e 'while (<>) {print "##$_"}' < infile > outfile
While we are at it:
gawk -i inplace '{print "##"$0}' infile
This uses the (comparatively new) inplace editing plugin for GNU awk 4.1.0+.