Results 1 to 3 of 3

Thread: grep for commas?

  1. #1
    Join Date
    May 2007
    Beans
    82

    grep for commas?

    Hi all,

    I have a load of comma-separated tables. Almost all lines have three entries, separated by commas e.g.

    Code:
    one,two,three
    Some lines have only two entries, and therefore one comma e.g.

    Code:
    one,two
    I want to get rid of the lines with two entries/one comma. It seems to me that a decent way to do this would be to use grep to find all the lines containing two commas..... But I can't figure out how to do it! Any pointers (or even alternate solutions I could put in a shell script) would be welcome.

    Thanks in advance,

    wrathkeg

  2. #2
    Join Date
    Jan 2008
    Beans
    1,532

    Re: grep for commas?

    Pretty simple:
    Code:
    [simian@splinter ~]$ cat temp 
    one,two,three
    a,b
    x,y,z
    qwe,ter,ert
    hi,there
    [simian@splinter ~]$ cat temp | grep ".*,.*,.*"
    one,two,three
    x,y,z
    qwe,ter,ert
    [simian@splinter ~]$

  3. #3
    Join Date
    May 2007
    Beans
    82

    Re: grep for commas?

    excellent! thanks. I had been putting "*" as the wildcard instead of ".*".
    best,
    wrathkeg

Bookmarks

Posting Permissions

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