Find the answer to your Linux question:
Results 1 to 2 of 2
Hi everyone, This is my first posting to the forum. I hope you can help me with this. I have a file called "donors.dat" that I am trying to display ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    1

    Using grep to search and display specific columns


    Hi everyone,

    This is my first posting to the forum. I hope you can help me with this.

    I have a file called "donors.dat" that I am trying to display from the last 5 columns (which is a zip code) only the ones that have a 2,3,4,5, and 7. Here is the first line:

    01 e smith edward 11 012 33308

    I tried this, but it didn't work:

    grep '[2-57]$....' donors.dat

    What am I doing wrong?

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    648
    Since you have the "$" in the regular expression, the last digit on the line must be in the set [ 2,3,4,5,7 ] and the .... would mean the next line has at least 4 characters.

    Have you tried looking for a much more complex regular expression? Such as:
    Code:
    '.* .* .* .* .* .* .*[2-57].*$'

Posting Permissions

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