If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Problem with 'grep' and 'cut'

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-05, 16:35
sbk sbk is offline
Registered User
 
Join Date: Jan 2005
Posts: 18
Unhappy Problem with 'grep' and 'cut'

Hi,

When I grep a text file for a pattern, it is printing all the occurences of that pattern to the console separated by some delimiter.

But I want to split all the occurences into separate strings using 'cut', I tried to use the following:

% grep '^steve' textfile | cut -f1 -d'\n'

If I use the above command it says "invalid delimiter". I don't know what delimiter grep inserts after printing out every occurrence of steve.

I want to do this because, if I say:
% grep '^steve' textfile
it is returning all the names such as:
steve
steven
stevenson
stevens

etc.. But I want only steve.

How should I do this?

Any help is very much appreciated.

Thanks a lot in advance,
sbk
Reply With Quote
  #2 (permalink)  
Old 01-28-05, 04:29
borsotti borsotti is offline
Registered User
 
Join Date: Jan 2005
Posts: 7
-w flag

Try grep -w

Marco
Reply With Quote
  #3 (permalink)  
Old 01-28-05, 13:30
sbk sbk is offline
Registered User
 
Join Date: Jan 2005
Posts: 18
Thumbs up

Hi Marco,

Thanks for the reply. It worked. But I also tried this:

/usr/xpg4/bin/grep -x 'steve' filename

which also worked for me.

regards,
sbk
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On