I want to use awk to sort content of an input file into different output files.
Simple example
Assuming the following input file:
$cat sample.txtSTART Unix Linux START Solaris Aix SCO
The awk program
awk '/START/{x="F"++i;}{print > x}' sample.txt
produces the following output into files:
$ cat F1START Unix Linux$ cat F2START Solaris Aix SCO
Actual usage scenario
When I apply this technique to my actual use case,
awk '/Certificate Revocation List (CRL):/{x="F"++i;}{print > x}' test_cert.pem
does not extract the contents starting from Certificate Revocation List (CRL):
Instead it gives following error:
awk: cmd. line:1: (FILENAME=test_cert.pem FNR=1) fatal: expression for `>' redirection has null string value
I tried putting the pattern in quotes and all, but it does not work, not sure if the pattern is multiword how we extract the content.
The test_cert.pem looks as follows:
Certificate Revocation List (CRL):
Version 2 (0x1)
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = XX, O = XXXXX, OU = 0003 374154744412350, CN = XXX
Last Update: Aug 15 04:37:16 2021 GMT
Next Update: Sep 23 03:47:16 2021 GMT
CRL extensions:
X509v3 CRL Number:
209
X509v3 Authority Key Identifier:
keyid:09:DF:3B:15:GE:10:08:D5:86:8F:5B:E7:E6:36:B9:A1:A8:1A:83:18
Revoked Certificates:
Serial Number: AAS60F19DABCDA8AGHIK3E4A59988AAFDA8E6
Revocation Date: Jan 29 12:45:09 2021 GMT
Serial Number: GGF0HHHABCDA8AGHIK3E4A599KKKAFDA8E6
Revocation Date: Jul 25 4:32:24 2021 GMT
Signature Algorithm: sha256WithRSAEncryption
1e:cc:8e:9d:gv:ae:eb:0a:67:95:4b:8b:b6:5d:9e:bd:48:42:
a5:25:e8:eb:b2:22:BV:42
-----BEGIN X509 CRL-----
MIIDLLKKARMCAQEwLLKKAOKONcNAQELBQYYUzvgfzELLLKKA1UEBhMCRlIxDzANBgNV
mZ7YI0YYUzvgrzYYUzvgz9Deb78UGbaedXkYYUzvgr5Hu1Zm16YYUzvgXo67IiNUI=
-----END X509 CRL-----