How to remove lines from text file not starting with certain characters (sed or grep)
grep, sed, text
Solution
Deleting lines:
With `grep`
From http://lowfatlinux.com/linux-grep.html :
The grep command selects and prints lines from a file (or a bunch of files) that match a pattern.
I think you can do something like this:
grep -v '^[\#\&\*]' yourFile.txt > output.txt
You can also use `sed` to do the same thing (check http://lowfatlinux.com/linux-sed.html ):
sed '^[\#\&\*]/d' yourFile.txt > output.txt
It's up to you to decide
Filtering lines:
My mistake, I understood you wanted to delete the lines. But if you want to "delete" all other lines (or filter the lines starting with the specified characters), then `grep` is the way to go:
grep '^[\#\&\*]' yourFile.txt > output.txt
Problem
How do I delete all lines in a text file which do not start with the characters `#`, `&` or `*`? I'm looking for a solution using `sed` or `grep`.