Reputation: 3451
I have a text file open in BBEdit/InDesign with email addresses on some lines (about a third of the lines) and name and date stuff on the other lines. I just want to keep the lines that have emails and remove all the others.
A simple pattern I can see to eliminate all the lines apart from those with email addresses on them is to have a negative match for the @
character.
I can't use grep -v pattern
because the Find and Replace implementation of grep
dialogue box just has the fields for Find pattern
and Replace pattern
. grep -something
options don't exist in this context.
Note, I am note trying to construct a valid email address test at all, just using the presence of one (or more) @
character to allow a line to stay, all other lines must be deleted from the list.
The closest I got was a pattern which hits only the email address lines (opposite outcome of my goal):
^((\w+|[ \.])\w+)[?@].*$
I tried various combination of ^.*[^@].*$
and more sophisticated /w
and [/w|\.]
in parentheses and escaping the @
with [^\@]
and negative look forwards like (!?)
.
I want to find these non-email address lines and delete them using any of these apps on OS X BBEdit/InDesign. I will use the command line if I have to. There must be a way using in-app Find and Replace with grep though I'd expect.
Upvotes: 0
Views: 1871
Reputation: 4847
As stated in the comments grep -v @ filename lists all lines without an @ symbol. You could also use grep @ filename > new_filename The file new_filename will consist only of lines with @. You can use this new file or delete all lines in the old file and paste contents of new file into it.
Upvotes: 0