Regarding to below command, I tried to insert space-separated contents of a log file into an array (arr), then make a condition to find and extract a specific string out of it. The problem is that the subject string is surrounded by single quotations and I don't know what is the proper syntax to involve those quotations in condition statement:
cat file.log | nawk '{split($0,arr," "); for (i=1;i<=NF;i++) if (arr[i]=='serviceid') printf ("%s,%s\n",arr[i],arr[i+1])}'
I've tried these:
cat file.log | nawk '{split($0,arr," "); for (i=1;i<=NF;i++) if (arr[i]=="'serviceid'") printf ("%s,%s\n",arr[i],arr[i+1])}'
cat file.log | nawk '{split($0,arr," "); for (i=1;i<=NF;i++) if (arr[i]=="\'serviceid\'") printf ("%s,%s\n",arr[i],arr[i+1])}'
I also tried to split based on single quotation like split($0,arr,/\'/), but it also fails.
Log
This is a part of the log: 'serviceid': 1002, is the part I'm trying to navigate to. When I execute print arr[301] it returns 'serviceid':. But when I command for (i=1;i<=NF;i++) if (arr[i] == 'serviceid',) {print $i} I get syntax error around single quotes.
'originTransactionID': '00720170311', 'serviceFeeExpiryDate': datetime.datetime(2019, 12, 23, 12, 0, tzinfo=), 'accountFlagsBefore': {'activationStatusFlag': True, 'supervisionPeriodExpiryFlag': False, 'supervisionPeriodWarningActiveFlag': False, 'negativeBarringStatusFlag': False, 'serviceFeePeriodExpiryFlag': False, 'serviceFeePeriodWarningActiveFlag': False}, 'serviceid': 1002, 'supervisionExpiryDate': datetime.datetime(2019, 12, 23, 12, 0, tzinfo=), 'dedicatedAccountInformation': [{'startDate': datetime.datetime(9999, 12, 31, 0, 0, tzinfo=), 'dedicatedAccountValue1': '0', 'dedicatedAccountID': 1