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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to export and echo.

Status
Not open for further replies.

christiniaroelin

Programmer
Sep 15, 2004
26
US
Hi gurus,

i have a file variab.dat which has thousands of line as below
END_DAY='21'
END_HR='16'
MIN='03'
MTH='11'
END_YR='05'
EXT_ENDED='MONDAY NOVEMBER 21ST, 2005 16.03.27'
EXT_START='MONDAY NOVEMBER 21ST, 2005 15.59.58'

my requirement is to export these vaiables to env.

export env END_DAY='21'
export env END_HR='16'
export env MIN='03'
export env MTH='11'
export env END_YR='05'
export env EXT_ENDED='MONDAY NOVEMBER 21ST, 2005 16.03.27'
export env EXT_START='MONDAY NOVEMBER 21ST, 2005 15.59.58'


i had a for loop to prefix export to each line followed by an echo. But it takes the space as a delimiter. Also, on echo it spits out the entire line and not just the value.(i.e on echo $END_DAY gives END_DAY='21'INSTEAD OF JUST '21'.

Could you please help me on this one.

Thanks in advance
christi.
 
In any bourne or korn shell:
env >/tmp/env.$$.1 # environment before
set -a
. ./path/to/variab.dat
env >/tmp/env.$$.2 # environment after
set +a
diff /tmp/env.$$.? # list of environment changes

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

thanks for your quick response.
I need to prefix the variables in a file with export sattement and run it. Since there are thousands of records in the file, i would nee dto loop it may be awk.
could you please guide me to achieve this.

thanks
Christi.
 
PHV,

The problem is that the file doenot have export stetment.
the data file (/tmp/variadates.dat)looks like

END_DAY='21'
END_HR='16'
MIN='03'
MTH='11'
END_YR='05'
EXT_ENDED='MONDAY NOVEMBER 21ST, 2005 16.03.27'
EXT_START='MONDAY NOVEMBER 21ST, 2005 15.59.58'

i need to export each of these variables and echo it.

i tried your earlier sugesstion but got no output.

Could you please help me on this.

Thanks for your time and help.

Christi.
 
tried your earlier sugesstion but got no output
Really ? Which shell ?
With your posted variab.dat and the following script:
env >/tmp/env.$$.1
set -a
. ./variab.dat
env >/tmp/env.$$.2
set +a
diff /tmp/env.$$.? | sed -n 's!> !!p'

I get the following output (bourne shell):
END_DAY=21
END_HR=16
END_YR=05
EXT_ENDED=MONDAY NOVEMBER 21ST, 2005 16.03.27
EXT_START=MONDAY NOVEMBER 21ST, 2005 15.59.58
MIN=03
MTH=11

or the following output (korn shell):
EXT_START=MONDAY NOVEMBER 21ST, 2005 15.59.58
END_YR=05
END_DAY=21
MTH=11
END_HR=16
MIN=03
EXT_ENDED=MONDAY NOVEMBER 21ST, 2005 16.03.27

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How about:

Code:
awk -F= ' { print "export " $0; print "echo " $0 } ' /tmp/variadates.dat > /tmp/exportem
. /tmp/exportem


Annihilannic.
 
Christi, the set -a provides for automatic exporting of variables while being set... PHV's solution should work.

from ksh manpage
-a allexport all new variable are created with export attribute


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top