Looking for the syntax to find a pattern in a file and remove the leading character from only that pattern.
For example, find -16
and remove the #
and save it to file.
Tried grep 12345-16 testfile2 | sed -e "s/^#//g"
which works but need to capture all entries into the input file.
Example:
From this:
something here 12345-14
something here 12345-15
# something here 12345-16
to this:
something here 12345-14
something here 12345-15
something here 12345-16
suggestions would be much appreciated.
You can do it with just sed
alone.
sed '/12345-16/s/^# *//' file
You can use -i
option of sed
to make in-file changes. /../
in front of sed
is a regex which only makes changes on lines that has that pattern. All remaining lines will not be touched and be printed out as is.
You don't need g
for global
here since you are only removing the leading #
. I have added a pattern of ^# *
which means #
or #
followed by spaces
at the start of the line. You can create your own pattern based on the structure of your 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