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

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) && ($3… 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

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}" | cut… Read More Use awk to repeat first column in CSV with unknown amount of columns

how to add floating number in shell?

a=-1.4 b=42273.85 awk "BEGIN {print ($a + $b)}" 42272.4 I am expecting result as 42272.45, what is wrong here? >Solution : You didn’t specify a precision so awk picked one for you (%.6g, the default for CONVFMT, see https://www.gnu.org/software/gawk/manual/gawk.html#Built_002din-Variables): a=-1.4 b=42273.85 awk -v a="$a" -v b="$b" ‘BEGIN {printf "%.2f\n", (a + b)}’ 42272.45 I’m also… Read More how to add floating number in shell?

awk transpose specific row to column and group them

I have the below data in a stdout: 09:13:32 19.2 cpu(1) 09:13:32 15.6 cpu(2) 09:13:32 16.7 cpu(3) 09:13:32 17.1 cpu(6) 09:13:32 17.1 cpu(7) 09:13:32 16.9 cpu(8) 09:13:32 16.7 cpu(9) 09:13:39 13.0 cpu(1) 09:13:39 9.2 cpu(2) 09:13:39 9.1 cpu(3) 09:13:39 7.1 cpu(6) 09:13:39 27.1 cpu(7) 09:13:39 46.9 cpu(8) 09:13:39 36.7 cpu(9) Trying to convert this to… Read More awk transpose specific row to column and group them

AWK code to remove rows integer or 0.5 decimal

I have a list of coordinates with fixed Lon and vary Lat like this: 75.5 36.5 37.4290504456 75.5 36.4 52.4753456116 75.5 36.3 66.4775466919 75.5 36.2 84.0023193359 75.5 36.1 111.997085571 75.5 36 172.343933105 75.5 35.9 111.806427002 75.5 35.8 83.5655899048 75.5 35.7 65.6402206421 75.5 35.6 50.8337936401 75.5 35.5 33.7828178406 But I would like to remove all rows… Read More AWK code to remove rows integer or 0.5 decimal