Software >> OS >> Unix >> Linux >> How to run awk program file from command line or shell script



1.      # awk -f <awk_program_file> <file_to_awk>
        or
        # awk '<awk_program_code>' <file_to_awk>

2.      # awk -F<field_separator_char> -f <awk_program_file> <file_to_awk>
        or
        # awk -F<field_separator_char> '<awk_program_code>' <file_to_awk>


Examples:

        gawk '{ sum +=  }; END { print sum }' file

        gawk -F: '{ print  }' /etc/passwd