Find the answer to your Linux question:
Results 1 to 2 of 2
When viewing a file, I use the following to produce the desired output: cat file | awk '{print $2, $6, $7, $8, $9, $10, $12}' I would like to use ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    4

    Grep help needed

    When viewing a file, I use the following to produce the desired output:

    cat file | awk '{print $2, $6, $7, $8, $9, $10, $12}'

    I would like to use grep to only display when $2 is a particular value.
    For example, if $2 is numeric, I may only want to see the output when $2 is 500.

    Please advise.
    Thanks

  2. #2
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665
    cat file | awk '$2 == "500" {print $2, $6, ..... $12}'

    Basicaly this says

    " if the second collum is equal to 500, than print yada yada."

    awk uses a patern / command structure. if the patern is matched, perform what is in the { }, the default just matches everything.
    I dont think you can restrict grep to a specific collum, but why would you want to, awk can do it just fine, and will do it faster (2 processes instead of one)
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

Posting Permissions

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