[NTLUG:Discuss] Finding different strings in a single file

Robert Citek robert.citek at gmail.com
Fri Dec 7 00:54:05 CST 2007


On Dec 6, 2007 11:26 PM, Leroy Tennison <leroy_tennison at prodigy.net> wrote:
> I have a situation where I need to check for several strings in a given
> file.  For example, are the following listed in /etc/services:
>
> chargen
> echo
> discard
> daytime

The -f option of grep would work:

echo 'chargen
echo
discard
daytime' > regex.list
grep -f regex.list /etc/services

You can also separate them with -e's.  For example:

grep -e chargen -e echo -e discard -e daytime /etc/services

Here's a version using a here document:

cat <<eof | grep -f - /etc/services
chargen
echo
discard
daytime
eof

Good luck and let us know what worked for you.

Regards,
- Robert



More information about the Discuss mailing list