Matching a regex metacharacter literally

Advertisements My understanding of Regex’s in AWK is that in order to match a Regex metacharacter literally (For example: +,$,^,*,etc) You must escape them, like so: awk -F ‘\\+’ ‘program here’ However I’ve noticed that you don’t actually need to do this with certain metacharacters, such as the "+" Input file: this|is|a|line this+is+a+line this?is?a?line this*is*a*line… Read More Matching a regex metacharacter literally

AWK script to print a single next word following a pattern match from Description field

Advertisements I have below CSV file: CreateDate, First Name, Last Name, Description 2023/03/25, Makvala, Anima, Your orders are 6157 and total value is 854257 2023/03/26, Leobwin, Saturnus, Your orders are 72 and total value is 1575675 2023/03/25, Boadicea, Pradip, Your orders are 52116 and total value is 29344357 I want below output Orders: 6157, Total… Read More AWK script to print a single next word following a pattern match from Description field

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