Unix Manuals

Quick Tips

NOTICE - New forum for all UNIX learners, users and programmers - click here

Find text within a file or set of files

UNIX® systems provide a useful command for searching for text within files. The command is named 'grep', for reasons which are unknown to us.

In its simplest form, the command syntax is:

grep text file

The command returns the whole of any lines in the file which contain the specified text.

For example:

$ grep John phone-numbers.txt
John Hammonds: 01-639-203-791
John Millerchip: 01-541-201-363
$

You may specify more than one filename, or use wildcards such as '*.txt'. Grep includes many useful options, such as the ability to list the line number that the match(es) appear on, or to list only lines which do not contain the specified text. Look at the man page for 'grep', and try some examples – it's a very useful command to get to know well.

Click here for the next Quick Tip

Home


Advertise on this site. See our privacy policy.
© Copyright 2000-2010, Tom Reader, All Rights Reserved.
UNIX is a registered trademark of The Open Group in the US and other countries.
For more information on the use of the UNIX trademark, click here.
The contents of this site are not connected with or endorsed by The Open Group in any way.

If this site has helped you, please consider sending us a small donation if you can afford it - thanks!