Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exporting variable from a file 2

Status
Not open for further replies.
Sep 22, 2004
27
US
HI group,

I have an output file with a single row and 24 fields seperated by spaces as shoen below:

000 156 317 441 605 800 156 316 441 605 800 999 00009 15659 31709 44119 60519 80029 15649 31699 44109 60509 80019 99999
i want to export (as an environment variable), each of the column, to be used for further processing.

for eg.export $var1 =000, $var2=156.........$var24=99999;

im trying to do something like beneath ..but without sucess..i'm new to unix..with just a couple of scripts written..

$ awk '{ for(i=1;i<=NF;i++) printf($i)}'< output.dat
000156317441605800156316441605800999000091565931709441196051980029156493169944109605098001999999$
$ export $1= awk '{printf($1)}'< output.dat
/bin/ksh: =: is not an identifier
$ export $1 | awk '{printf($1)}'< Joutput.dat
/bin/ksh: {printf($1)}: is not an identifier

plz provide some advice on how to go abt this.

Thanks in advance!!
 
Code:
awk '{ for(i=1;i<=NF;i++) printf("export var"i"="$i"\n")}' < data.raw > varout.sh
will save the variables to a script varout.sh.
You will need to source it:
Code:
. varout.sh
or
Code:
source varout.sh
afaik you may not force the parent/ the caller of the script, to know these variables.

seeking a job as java-programmer in Berlin:
 
Something like this ?
eval $(awk '{printf "export";for(i=1;i<=NF;++i)printf " var%d=%s",i,$i;printf "\n"}' output.dat)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top