Re: Grep For Line Containing 1or 2 Words
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 01/26/05
- Next message: Captain Dondo: "Re: My modules are not being loaded at boot."
- Previous message: Mike Cox: "Re: My modules are not being loaded at boot."
- In reply to: Buck Turgidson: "Grep For Line Containing 1or 2 Words"
- Next in thread: Andrew Schulman: "Re: Grep For Line Containing 1or 2 Words"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Jan 2005 00:58:25 GMT
On Tue, 25 Jan 2005 at 21:47 GMT, Buck Turgidson wrote:
> Looking for help in writing a grep (or perl) that will pull from a text file
> those lines containing one or two "words". I want to reject any line that
> contains more than 2 words (a sentence).
>
> Appreciate any help from text processing experts.
To get all lines with no more than 2 words:
awk 'NF <= 2' FILENAME
To eliminate empty lines also:
awk 'NF && NF <= 2' FILENAME
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: Captain Dondo: "Re: My modules are not being loaded at boot."
- Previous message: Mike Cox: "Re: My modules are not being loaded at boot."
- In reply to: Buck Turgidson: "Grep For Line Containing 1or 2 Words"
- Next in thread: Andrew Schulman: "Re: Grep For Line Containing 1or 2 Words"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|