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

usage of grep cmd

Reply to Message Icon

Original Message
Name: urmilaravishankar
Date: September 30, 2007 at 07:05:35 Pacific
Subject: usage of grep cmd
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


Report Offensive Message For Removal


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

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

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


Report Offensive Follow Up For Removal

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

$ 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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: usage of grep cmd 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 1 Day.
Discuss in The Lounge