I have a function that takes a filename. It then runs a command and filters the output (exclusive) between two patterns, then it outputs comma separated values with the filename output of the command.
Here is the function and the expected output:
get_cons_obs() {
local line="${1}"
"command" -i "${line}" 2>&1 \
| awk '/^ERROR$/{print "ERROR"} /^START$/{flag=1;next} /^END$/{flag=0} flag' \
| xargs printf "${line},%s\n"
}
file01,thing01
file01,thing02
file01,thing03
.
.
.
Is it possible to combine awk
command and the xargs printf
command? I can't seem to append the "flagged" lines with the $line
variable.