How to parse each line separately with awk?

Advertisements A multi-line variable LOG_BUF is set in a bash script parse.sh. Then the variable is parsed with awk, printing all rows containing pat: #!/bin/bash LOG_BUF=$(cat <<-END pat TEST_a pat TEST_b TEST_c pat TEST_d END ) echo ${LOG_BUF} | awk ‘BEGIN{}; /pat/{printf("%d %s", NR, $0); printf("\n")}; END{printf("\n")}’ The expected output is: $ ./parse.sh 1 mem… Read More How to parse each line separately with awk?

Print rows where one column is the same but another is different

Advertisements Given files test1 and test2: $ cat test* alert_name,id,severity bar,2,1 foo,1,0 alert_name,id,severity foo,1,9 bar,2,1 I want to find rows where name is the same but severity has changed (ie foo) and print the change. I have got this far using awk: awk ‘BEGIN{FS=","} FNR>1 && NR==FNR { a[$1]; next } ($1 in a) &&… Read More Print rows where one column is the same but another is different

Use awk to repeat first column in CSV with unknown amount of columns

Advertisements I’m trying to create a 2 column CSV, where the first column is a name, and the second column is the value. I am able to do this with a nested loop, but I’m positive that AWK can do this much faster DATA=’POLICY_NAME01,VM001,VM002,VM003 POLICY_NAME02,VM004 POLICY_NAME03,VM005,VM006′ IFS=$’\n’ for LINE in $DATA; do POLICY=$(echo "${LINE}" |… Read More Use awk to repeat first column in CSV with unknown amount of columns