![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell script to read file into variable | aspect_p | Shell Programming and Scripting | 7 | 03-21-2008 09:12 AM |
| Accessing variables of one shell script in another shell script | rsendhilmani | Shell Programming and Scripting | 1 | 04-30-2007 05:43 AM |
| Shell script for accessing a file in the network drive and invoking oracle sql loader | sayydevara | Shell Programming and Scripting | 0 | 03-20-2007 12:54 PM |
| Read variable from file in a C shell script | haouesse | Shell Programming and Scripting | 2 | 11-07-2006 06:34 AM |
| Accessing var from .profile into shell script | videsh77 | Shell Programming and Scripting | 7 | 05-28-2005 09:21 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
||||
|
||||
|
accessing shell script variable in file
Hi,
I have a shell script in which there is a file conn_$temp where $temp has the pid of the shell script. in this shell script i have an embedded awk script that must read the file while ((getline < "conn_$temp") > 0) However due to the "$temp" in the file name, the awk script is unable to open the file. How can i fix this problem? basically i need to append the pid to the file name so that for each session the file names will be different. Thanks for your help in advance. Himani |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Can you post your script please ?
|
|
#3
|
||||
|
||||
|
Hi,
This is the script : temp=`echo $$` echo $temp tempvar1=`some values here` tempvar2=`somme other values here` diff conndifffile1_$temp conndifffile2_$temp | egrep '^< |> ' | uniq -u > conndifffile3_$temp awk -v val1=${tempvar1} -v val2=${tempvar2} -F , 'BEGIN { while ((getline < "conndifffile3_$temp") > 0) { if( substr($1,1,1) == "<" ) { sub(/</,val1,$1) sub(/ /," , ",$1) } else { sub(/>/,val2,$1) sub(/ /," , ",$1) } print $1,",",$2,",",$3,",",$4,",",$5 } }' Files conndifffile1_$temp conndifffile2_$temp have some values stored in them. Thanks, Himani |
|
#4
|
||||
|
||||
|
Try this,
Code:
temp=`echo $$`
echo $temp
tempvar1=2
tempvar2=3
diff conndifffile1_$temp conndifffile2_$temp | egrep '^< |> ' | uniq -u > conndifffile3_$temp
INPUT_FILE=conndifffile3_$temp
gawk -v val1=${tempvar1} -v val2=${tempvar2} -v val3=${INPUT_FILE} 'BEGIN {
while ((getline < val3 ) > 0)
{
if( substr($1,1,1) == "<" )
{
sub(/</,val1,$1)
sub(/ /," , ",$1)
}
else
{
sub(/>/,val2,$1)
sub(/ /," , ",$1)
}
print $1,",",$2,",",$3,",",$4,",",$5
}
}'
|
|
#5
|
||||
|
||||
|
Hi,
Its working !!! thanks. But i have a doubt .. i was naming the files with the pid so that if different users login then the files for them would be seperate and not interfere with each other. If the variable INPUT_FILE is assigned the file3 name then wouldnt that sometimes make files of different users to be lost? Thanks, Himani |
|
#6
|
||||
|
||||
|
Quote:
|
|
#7
|
||||
|
||||
|
Thanks for ur help
|
||||
| Google The UNIX and Linux Forums |