Question

How can I call an awk script from an awk script and assign the output of the first to a variable in the second?

I have an awk script that reads files each night, checks each line of data and writes to a new file. I need to add in some additional formatting to one of the fields. I already have a standalone awk script that does the formatting so all I need to do is call this awk script for the appropriate fields and assign the value that is normally printed to a variable.

To put it in context, the following prints the required formatting to the screen (because that's what title_case.awk does), but I can’t use the value for further processing.

print old_name | ("/production/bin/title_case.awk")

so I need something like the following:

new_name = 'old_name | ("/production/bin/title_case.awk")

Thanks,

Ger

Was it helpful?

Solution

You can try using getline into a variable ( http://www.gnu.org/software/gawk/manual/gawk.html#Getline_002fVariable_002fPipe )

("/production/bin/title_case.awk "old_name) | getline new_name
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top