I need i padded to 3 places, e.g. 001. I’m trying printf and sprintf per this suggestion, but no variation I try works.
awk '/BEGIN/{i++}/BEGIN/,/END/{print > "mozcert-" i ".pem"}' ca-certificates.crt
First day with awk and sprintf, unsure of proper syntax. Here are some attempts.
awk '/BEGIN/{i++} /BEGIN/,/END/ {print > "mozcert-" printf "%03d\n",i ".pem"}' ca-certificates.crt
awk '/BEGIN/{i++} /BEGIN/,/END/ {print > "mozcert-}" {printf "%03d\n",i} {".pem"}' ca-certificates.crt
awk '/BEGIN/{i++} /BEGIN/,/END/ {print > "mozcert-" {sprintf(^C03d\n",i} ".pem"}' ca-certificates.crt
>Solution :
The function to format output is printf (or sprintf if you don’t want to print immediately).
awk '/BEGIN/{filename = sprintf("mozcert-%03i.pem", ++i)}
/BEGIN/,/END/{print > filename}' ca-certificates.crt