For Programmers: Free Programming Magazines  


Home > Archive > AWK > May 2006 > awk and assign output to a variable









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author awk and assign output to a variable
rogv24@yahoo.com

2006-05-22, 6:57 pm

How would you assign the output to a variable:

awk '{print $1 }' file.one?

Bob Harris

2006-05-22, 6:57 pm

In article
<1148325766.546120.224450@j55g2000cwa.googlegroups.com>,
rogv24@yahoo.com wrote:

> How would you assign the output to a variable:
>
> awk '{print $1 }' file.one?


Assuming ksh, bash, or POSIX Shell

variable=$(awk '{print $1}' file.one)

or

set -- $(awk '{print $1, $2, $3}' file.one)
var1=$1
var2=$2
var3=$3

csh, tcsh, bourne shell

variable=`awk '{print $1} file.one`
or
set -- `awk '{print $1, $2, $3}' file.one`
var1=$1
var2=$2
var3=$3
rogv24@yahoo.com

2006-05-23, 7:57 am

Thank you so much.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com