kornShellScripter
Programmer
In line with Ferherke's tip to try to get nawk to do as much work as possible, I replaced:
OUT_TEXT_DATE=$(grep 'AP BALANCES AS AT' $FILE_NAME | nawk '{print $6} | head -1'
with
OUT_TEXT_DATE=$(nawk '/AP BALANCES AS AT/{print $6}' $FILE_NAME | head -1)
(I'm not a nawk person so I'm learning as I go here and discovering new things)
BUT
I have a problem. My script takes input from a variety of locations, and today I've found that the header in one of the reports is not "AP BALANCES AS AT" but is instead "POSTING PERIOD"
So what I'm thinking of doing is putting the string to search for in my ever-growing array (as I have done in other sections of the script)
But then the single quote in my nawk script won't allow that expansion - this won't work:
OUT_TEXT_DATE=$(nawk '/${COUNTRY_CODE[$INDEX_COUNT]}/{print $6}' $FILE_NAME | head -1)
because the single quotes prevent the expansion. And I'm reluctant to use double quotes because I think I want to protect the $6 (and others elsewhere in the script) to nawk.
So it looks like I'm going back to:
OUT_TEXT_DATE=$(grep "${COUNTRY_CODE[$INDEX_COUNT]}" $FILE_NAME | nawk '{print $6}' | head -1)
which is now using two tools (grep and nawk) when one could do.
Of course, all this works, but I'd like the code to be efficient as well as readable/supportable so any suggestions would be most welcome.
(PS: yes, I think that $(head -1) could be replaced with ';exit' to nawk - something else I discovered recently from help on this forum with getline)
OUT_TEXT_DATE=$(grep 'AP BALANCES AS AT' $FILE_NAME | nawk '{print $6} | head -1'
with
OUT_TEXT_DATE=$(nawk '/AP BALANCES AS AT/{print $6}' $FILE_NAME | head -1)
(I'm not a nawk person so I'm learning as I go here and discovering new things)
BUT
I have a problem. My script takes input from a variety of locations, and today I've found that the header in one of the reports is not "AP BALANCES AS AT" but is instead "POSTING PERIOD"
So what I'm thinking of doing is putting the string to search for in my ever-growing array (as I have done in other sections of the script)
But then the single quote in my nawk script won't allow that expansion - this won't work:
OUT_TEXT_DATE=$(nawk '/${COUNTRY_CODE[$INDEX_COUNT]}/{print $6}' $FILE_NAME | head -1)
because the single quotes prevent the expansion. And I'm reluctant to use double quotes because I think I want to protect the $6 (and others elsewhere in the script) to nawk.
So it looks like I'm going back to:
OUT_TEXT_DATE=$(grep "${COUNTRY_CODE[$INDEX_COUNT]}" $FILE_NAME | nawk '{print $6}' | head -1)
which is now using two tools (grep and nawk) when one could do.
Of course, all this works, but I'd like the code to be efficient as well as readable/supportable so any suggestions would be most welcome.
(PS: yes, I think that $(head -1) could be replaced with ';exit' to nawk - something else I discovered recently from help on this forum with getline)