Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    18

    Unhappy Unanswered: 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

  2. #2
    Join Date
    Jan 2005
    Posts
    7

    -w flag

    Try grep -w

    Marco

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •