0

For example, I want do remove all lines in a textile that do not contain the character '@'

I have already tried to use sed like so

sed '/@/!d' data.txt

What am I missing? Shouldn't this work?

John Kugelman
  • 330,190
  • 66
  • 504
  • 555

2 Answers2

1

I prefer using ed over the non-standard sed -i, especially if it needs to be portable:

printf "%s\n" "v/@/d" w | ed -s filename

This deletes every line that doesn't contain a @, and saves the changed file back to disc.

Shawn
  • 38,372
  • 3
  • 13
  • 43
0
sed -n '/@/p' [file]
  • -n suppress default printing
  • /@/ match on @ anywhere on the line
  • p print if it matches

Add -i for in-place editing of the file (if supplied).

Ted Lyngmo
  • 60,763
  • 5
  • 37
  • 77