I want to add hashes to all the lines in a regular text file. I'm fine with both the use of terminal and GUI—I just need to get it done.
I want to add hashes to all the lines in a regular text file. I'm fine with both the use of terminal and GUI—I just need to get it done.
You can use
sed
to do that: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
While we are at it:
This uses the (comparatively new) inplace editing plugin for GNU awk 4.1.0+.
Here's a
bash
way:(In the
bash
shell, runningread -r
with no other arguments works likeIFS= read -r REPLY
.)This is stylistically inspired by beav_35's perl solution, which I admit probably runs much faster for huge files, since
perl
may be expected to be more efficient than a shell when it comes to text processing.sed -i
is not POSIX-standard, so if you are a purist you will want to useed
:Here's an easier
perl
way than presented elsewhere:This (ab)uses the fact that
perl -p
prints the line after executing the command given in-e
.You can use Vim in Ex mode:
%
select all liness
substitutex
save and closeCan be done with python's mapping function and redirecting stdin:
Save the output to new file and use it instead of original