Find the answer to your Linux question:
Results 1 to 2 of 2
i'm trying to convert this awk command from command line into an awk script, but just cannot get it to work: awk -F: '$5 ~ /A/ {Acount++; print Acount}' file ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    3

    awk script help


    i'm trying to convert this awk command from command line into an awk script, but just cannot get it to work:

    awk -F: '$5 ~ /A/ {Acount++; print Acount}' file

    this is what i have after my BEGIN

    $5~/A/Acount++ {print Acount}

    am i missing something here? this just prints out the count for everyline, not counting lines on 5th field that match 'A'

    any help is appreciated.

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Your script should look like this:

    Code:
    /path/to/awk -f
    
    BEGIN {
      FS = ":"
      }
    $5 ~ /A/ {
        Acount++
        }
    END {
      print Account
      }
    And you should invoke it like this:

    Code:
    awk -f <script_name> <input_filename>

Posting Permissions

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