I am new to using sed command and my question might probably a basic one.
I am having a log file and I am trying to grep only the errors and extract some required values from the error lines.
I am facing a problem when there are more than 9 pattern groups in sed. I tried using sed -e to have multiple sed but it does not seem to work.
Commands tried
Command #1:
grep ERROR file | sed -n 's_.*key1=\([0-9]*\), key2=\([0-9]*\),.* key3=(.*\), key4=\([a-zA-Z0-9_]*\),.* key5=\([A-Z0-9]*\),.*key6=\([a-zA-Z0-9]*\),.*key7=\([0-9]*\), key8=\(.*\), key9=\(.*\), key10=\(.*\)}.*_\1,\2,\3,\4,\5,\6,\7,\8,\9,\10_p'
In the above output, number 10 is being printed instead of the value matching 10th pattern
Command #2:
This AWK command, almost did what I wanted though I am not able to format it as proper comma separated values.
awk -F "\n" '/ERROR/ && match($0,/key1=([0-9]*), key2=([0-9]*),.*key3=(.*),key4=([a-zA-Z0-9_]*),.*key5=([a-z]*).*key6=([a-z]*),.*key7=([A-Z0-9]*),.*key8=([0-9]*).*key9=([a-zA-Z0-9]*)/,a) {
for (i=1; i in a; i++) {
printf "%s%s", a[i], (i<length(a) ? OFS : ORS)
}
printf "\n"
}' TestFile