linuxbashtextsed

Delete lines in a text file that contain a specific string with /


I have a text file with dates in this format: 27/8/2019 I would like to remove all lines except for those that contain 27/8/2019

If I use sed, that would be:

sed -i '/pattern/!d' file.txt

The problem is that when I have a pattern with '/', I have the next error:

sed: -e expression #1, char 5: unknown command: `8'

Solution

  • Escape the slashes:

    sed -i '/27\/8\/2019/!d' file.txt