I need to add a #
before any line containing the pattern "000", e.g., consider this sample file:
This is a 000 line.
This is 000 yet ano000ther line.
This is still yet another line.
If I run the command, it should add #
to the front of any files where "000" was found. The result would be this:
#This is a 000 line.
#This is 000 yet ano000ther line.
This is still yet another line.
The best I can do is a while loop, like this, which seems too complicated:
while read -r line
do
if [[ $line == *000* ]]
then
echo "#"$line >> output.txt
else
echo $line >> output.txt
fi
done < file.txt
How can I add a #
to the front of any line where a pattern is found?
Can I Have Multiple Gmail Accounts? The short answer is, "Yes, you can have multiple Gmail accounts." Many professionals have both a personal Gmail account and a work Gmail account tethered to their CRM.
The following sed command will work for you, which does not require any capture groups:
sed /000/s/^/#/
Explanation:
/000/
matches a line with 000
s
perform a substitution on the lines matched above#
) at the beginning of the line (^
)This might work for you (GNU sed):
sed 's/.*000/#&/' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With