Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using sed to delete lines containing slashes /

Tags:

regex

bash

sed

I know in some circumstances, other characters besides / can be used in a sed expression:

sed -e 's.//..g' file replaces // with the empty string in file since we're using . as the separator.

But what if you want to delete lines matching //comment in file?

sed -e './/comment.d' file returns

sed: -e expression #1, char 1: unknown command: `.'
like image 719
user1011471 Avatar asked Sep 07 '25 12:09

user1011471


1 Answers

You can use still use alternate delimiter:

sed '\~//~d' file

Just escape the start of delimeter once.

like image 152
anubhava Avatar answered Sep 10 '25 02:09

anubhava