LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to pipe/redirect awk output into a variable? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-pipe-redirect-awk-output-into-a-variable-522657/)

johnpaulodonnell 01-25-2007 07:22 AM

how to pipe/redirect awk output into a variable?
 
Hi.

I have a simple awk command to read the number of records in a file which is passed to it. I'd like to then save this output as a variable within a bash script. How is this done? The pipe I use below doesn't work.

awk '{ ++x } END { print x }' file_name | read my_variable

Similarly I get an error when I try:

read my_variable < awk '{ ++x } END { print x }' file_name

Thanks.

Guttorm 01-25-2007 07:49 AM

Hi

my_variable=$(command)

try:
my_variable=$(awk '{ ++x } END { print x }' file_name)

johnpaulodonnell 01-25-2007 07:54 AM

That's it.

Thanks!


All times are GMT -5. The time now is 02:32 PM.