I have a file that has content like this:
apple b\all cat \34 egg
I want to remove all lines containing backslashes. I tried using
sed '/\/d' pdataf.txt
But it didn't work. What should I try?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
You need to escape the backslash (escape character) in order to replace it. And if your version of sed supports it, the -i (in-place) option will do the edits on your file without you having to provide an intermediate file. Also, if you use the -i option, note that it accepts a (recommended!) backup file extension, however if you do not provide one, it is useful to precede your sed command with -e to inform sed that you are not using a backup file extension.
Putting it all together:
# Run sed to remove lines with backslash in them $ sed -i -e '/\\/d' pdataf.txt # Cat your file to confirm edits $ cat pdataf.txt apple cat egg