I try to delete all lines that begin with some optional special chars followed by blubb
:
That's the lines I want to match:
#blubb
*blubb
-blubb
blubb
That should do it, but doesn't work :(
sed "/^.?blubb$/d" -i special.conf sed "/^[#*-]?blubb$/d" -i special.conf
Has somebody the right solution?
To begin with, if you want to delete a line containing the keyword, you would run sed as shown below. Similarly, you could run the sed command with option -n and negated p , (! p) command. To delete lines containing multiple keywords, for example to delete lines with the keyword green or lines with keyword violet.
N command reads the next line in the pattern space. d deletes the entire pattern space which contains the current and the next line. Using the substitution command s, we delete from the newline character till the end, which effective deletes the next line after the line containing the pattern Unix.
Although the simple searching and sorting can be performed using sed command, using regex with sed enables advanced level matching in text files. The regex works on the directions of characters used; these characters guide the sed command to perform the directed tasks.
Use this sed command:
sed -i.old '/^[#*-]\{0,1\}blubb/d' special.conf
OR
sed -i.old -E '/^[#*-]?blubb/d' special.conf
OR
sed -i.old -r '/^[#*-]?blubb/d' special.conf
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