1

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
  • 349,597
  • 67
  • 533
  • 578

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
  • 47,241
  • 3
  • 26
  • 60
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
  • 93,841
  • 5
  • 60
  • 108