I need to delete first character at each line only if the given pattern matches with that line.
I have tried by replacing the first character with space, but space is appending at the each line.
sed -e '/#/s/^/ /' 2.txt > 1.txt
I need to remove the # from each line. Kindly suggest me how to make this.
You need to add a dot after ^, so that it would match the first character.
sed -e '/#/s/^./ /' 2.txt > 1.txt
Example:
$ cat file
foo
foo bar #
$ sed -e '/#/s/^./ /' file
foo
oo bar #
If you want to remove the starting # symbol then you don't need to use a search pattern,
sed 's/^#//g' file1 > file2
You can use this:
sed 's/^#//' 2.txt > 1.txt
It replaces the # at the beginning of a line by an empty string, if there is no # at the beginning of the line, then it leaves that line untouched.
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