Computing.Net > Forums > Linux > usage of grep cmd

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

usage of grep cmd

Reply to Message Icon

Name: urmilaravishankar
Date: September 30, 2007 at 07:05:35 Pacific
OS: linux
CPU/Ram: AMD anthlon,32 MB
Comment:

Hi
Kindly give me the exact usage of grep such that it should display only lines with single words.
In awk its cat filename|awk 'NF<2 {print $0}' will display lines with single word only



Sponsored Link
Ads by Google

Response Number 1
Name: Guy
Date: October 6, 2007 at 07:48:51 Pacific
Reply:

This should get you what you want most of the time:

grep -E "^[A-Za-z0-9]+$" filename


0

Response Number 2
Name: Luke Chi
Date: February 7, 2008 at 14:13:38 Pacific
Reply:

$ grep "^[^ ]*$" infile.txt

Example:

$ cat infile.txt
This is a test
file
to test how
grep can
grep the
lines
with only one
word.

$ grep "^[^ ]*$" infile.txt
file
lines
word.

Luke Chi


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: usage of grep cmd

store result of grep -e to variable www.computing.net/answers/linux/store-result-of-grep-e-to-variable/15837.html

Showing processor usage by process www.computing.net/answers/linux/showing-processor-usage-by-process/17542.html

grep in shellscript www.computing.net/answers/linux/grep-in-shellscript/21620.html