Help with awk and substr

I have the following to find lines matching "COMPLETE" and extract parts of it using substr.

sed -n "/COMPLETE/p" 1.txt | awk 'BEGIN { FS = "\" } {printf"%s %s:%s \n", substr($3,17,3),substr($6,4,1), substr($7,4,1)}' | sort | uniq > temp.txt

Worked fine until the numbers in 2nd & 3rd substr became 1 or 2 digits long. Any ideas of how I should do this? Should I match pattern instead of getting substr?
Example:

aaa...455/bbb/ccc/ddd/eee/fff 8/ggg 10/hhh/

Please, post a sample of your input file and the required output.

Jean-Pierre.

aaa\bb,bbb #1\ccc 234567890111\ddd\eee\ff#8\g #1\whatever
aaa\bb,bbb #1\ccc 234567890111\ddd\eee\ff#8\ g #10\whatever
aaa\bb,bbb #1\ccc 234567890111\ddd\eee\ff#84\ g #1\whatever

Output:
111 8:1
111 8:10
111 84:1

You can do something like that :

awk -F '\' '{ sub(/.*#/, "", $6); sub(/.*#/, ":", $7); print substr($3,14,3), $6 $7 }' 

Jean-Pierre.

1 Like

This works well. I could neve figure out how to filter before feeding the text to sub() . Went back to my old ways of filtering /COMPLETED/ using sed and then feeding it to above script.

awk -F '\' '/COMPLETE/ { sub(/.*#/, "", $6); sub(/.*#/, ":", $7); print substr($3,14,3), $6 $7 }' 1.txt | sort -u > temp.txt

Jean-Pierre.