The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 08-03-2007
HIMANI's Avatar
Registered User
 

Join Date: Jul 2007
Posts: 18
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
Reply With Quote
Forum Sponsor
  #2  
Old 08-03-2007
kamitsin's Avatar
Registered User
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Can you post your script please ?
Reply With Quote
  #3  
Old 08-03-2007
HIMANI's Avatar
Registered User
 

Join Date: Jul 2007
Posts: 18
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
Reply With Quote
  #4  
Old 08-04-2007
kamitsin's Avatar
Registered User
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
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
}
}'
Reply With Quote
  #5  
Old 08-04-2007
HIMANI's Avatar
Registered User
 

Join Date: Jul 2007
Posts: 18
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
Reply With Quote
  #6  
Old 08-04-2007
kamitsin's Avatar
Registered User
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Quote:
If the variable INPUT_FILE is assigned the file3 name then wouldnt that sometimes make files of different users to be lost?
- No it won't happen because the PID will always be different
Reply With Quote
  #7  
Old 08-06-2007
HIMANI's Avatar
Registered User
 

Join Date: Jul 2007
Posts: 18
Thanks for ur help
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0