Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

I was struggling with this on Mac. Plus, I needed to do it using variable replacement. So

So I used:

sed -i '' "/$pattern/d" $file

where $file is the file where deletion is needed and $pattern is the pattern to be matched for deletion. Picked

I picked the '' from this comment. The

The thing to note here is use of double quotes in "/$pattern/d". Variable won't work when we use single quotequotes.

I was struggling with this on Mac. Plus, I needed to do it using variable replacement. So I used:

sed -i '' "/$pattern/d" $file

where $file is file where deletion is needed and $pattern is the pattern to be matched for deletion. Picked the '' from this comment. The thing to note here is use of double quotes in "/$pattern/d". Variable won't work when we use single quote.

I was struggling with this on Mac. Plus, I needed to do it using variable replacement.

So I used:

sed -i '' "/$pattern/d" $file

where $file is the file where deletion is needed and $pattern is the pattern to be matched for deletion.

I picked the '' from this comment.

The thing to note here is use of double quotes in "/$pattern/d". Variable won't work when we use single quotes.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I was struggling with this on Mac. Plus, I needed to do it using variable replacement. So I used:

sed -i '' "/$pattern/d" $file

where $file is file where deletion is needed and $pattern is the pattern to be matched for deletion. Picked the '' from this commentcomment. The thing to note here is use of double quotes in "/$pattern/d". Variable won't work when we use single quote.

I was struggling with this on Mac. Plus, I needed to do it using variable replacement. So I used:

sed -i '' "/$pattern/d" $file

where $file is file where deletion is needed and $pattern is the pattern to be matched for deletion. Picked the '' from this comment. The thing to note here is use of double quotes in "/$pattern/d". Variable won't work when we use single quote.

I was struggling with this on Mac. Plus, I needed to do it using variable replacement. So I used:

sed -i '' "/$pattern/d" $file

where $file is file where deletion is needed and $pattern is the pattern to be matched for deletion. Picked the '' from this comment. The thing to note here is use of double quotes in "/$pattern/d". Variable won't work when we use single quote.

Source Link
Aniket Sinha
  • 6k
  • 6
  • 39
  • 50

I was struggling with this on Mac. Plus, I needed to do it using variable replacement. So I used:

sed -i '' "/$pattern/d" $file

where $file is file where deletion is needed and $pattern is the pattern to be matched for deletion. Picked the '' from this comment. The thing to note here is use of double quotes in "/$pattern/d". Variable won't work when we use single quote.