Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i've seen a solution for this with single line awk, but what if i want to extract the variables from the awk END section back to the shell? any ideas?
thanks.

Hi:
I'm not certain, but I think you're aware of command substituion. Here's an example:
x=`echo ""|nawk ' { print "Hi" }
END { print "Ending" } '`this if you use ksh:
x=$(echo ""|nawk ' { print "Hi" }
END { print "Ending" } ')Now, if you want to get just the END output into a variable without the other statement you can redirect to a file and read the file.
x=$(echo ""|nawk ' { print "Hi" }
END { print "Ending" > "ending.txt"} ')y=$(cat ending.txt)
echo "y is $y"You can append to the ending.txt file using >>.
Regards,
Nails

great. i was wondering if there was syntax similar to the " -v awkvar="$shellvar" " method for inputting shell variableds, but the file output solution works perfect for what i want. thanks.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |