Access value outside awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Access value outside awk
# 1  
Old 11-26-2007
Access value outside awk

Hello I am new to Unix. Please help me out.
My Scenario:
I am first collecting all the file names present in the directory with structure myinfo/yourinfo/supplierinfo
I have four files with the names myCollector.java, yourCollector.java, someCollector.java, everyCollector.java. in the directory.

I am reading the file name and i am getting myinfo/yourinfo/supplierinfo/myCollector.java. and the such string for other files.
I am spliting it to get only substring "myCollector" from the above string which is stored in variable progexe.

How can i access this variable outside awk so that i can run that java class.

#!/bin/bash
source ~/.login
progexearr=""
pruneclass=""
pruneclass="$(find myinfo/yourinfo/supplierinfo -name "*llector.java*")"

echo "$pruneclass"| awk '{
z=split($0,flds," ")
for(i=1;i<=z;i++)
progcompile=flds[i]
p2 = length(progcompile)
exetemp=substr(progcompile,41,p2)
progexe=substr(exetemp,0,length(exetemp)-5)
# Please dont worry about the above code
progexearr[i]=progexe
print progexe # i am getting myCollector, yourCollector,someCollector and everyCollector. How can i access the value of variable and array outside awk.
print progexearr[i]
}'
How can i access value of progexearr array out awk..

somebody please help...

thanks
# 2  
Old 11-26-2007
It looks to me like you could put back ticks (`) around the entire awk statement.
Example:
Code:
echo "some stuff for awk to process" | awk '{ print $2 }'

Prints the string "stuff"
Example of trapping this returned string
Code:
myvariable=`echo "some stuff for awk to process" | awk '{ print $2 }'`
if [ "$myvariable" = "stuff" ]
then
    echo "Yay, we found stuff"
else
    echo "Something went wrong with the script"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable To access array in awk

Hi, i have the following code in which i am passing array tldn in awk using -v option & despite of that condition is not getting matched,can somebody suggest how to handle shell arrays in awk tcount=(9875 9667) awk -F"\t" -v ltldn="${tldn}" 'NR==FNR {POSTPAIDMDNS=$2"|"$3;next} ... (6 Replies)
Discussion started by: siramitsharma
6 Replies

2. Solaris

samba read write access to owner and no access to other users

Hi All, I want to configure samba share permission so that only directory creator/owner has a read and write permission and other users should not have any read/write access to that folder.Will that be possible and how can this be achieved within samba configuration. Regards, Sahil (1 Reply)
Discussion started by: sahil_shine
1 Replies

3. Shell Programming and Scripting

Need help with awk and access log

when i run this command: tail -200 /var/log/httpd/access_log | awk -F'' '{sub(/:*$/,"",$2);print $2}' i get: 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

Access log field - using awk to pull date/time

hey guys. the following line is a line taken from apache's access_log 10.10.10.10 - jdoe "GET /images/down.gif HTTP/1.1" 304 I'm concerned about the field that has the date and time in it. if assuming the delimiter in the file is a space, then the fourth field will always have the date... (5 Replies)
Discussion started by: SkySmart
5 Replies

5. Shell Programming and Scripting

Parsing out access.log with awk and grep

In part of my script I use awk to pull out the urls. awk '{print $8}' then I take them and send them to grep.` Some of them are straight .com/ or .org or whatever (address bar entries), while others are locations of images, js, etc. I'm trying to only pull any line that ends with .com/... (11 Replies)
Discussion started by: druisgod
11 Replies

6. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

7. Shell Programming and Scripting

Access Awk Variables Outside Scope

My awk script searches for specified patterns in a text file and stores these values into mem variables. Once this is done I want to Insert these values into a table. How can I avail of the variable values outside the scope of awk script.... One method that I have tried is to write the... (7 Replies)
Discussion started by: Amruta Pitkar
7 Replies

8. UNIX for Dummies Questions & Answers

Access value outside awk or split value of array

Hello I am new to Unix. Please help me out. My Scenario: I am first collecting all the file names present in the directory with structure myinfo/yourinfo/supplierinfo I have four files with the names myCollector.java, yourCollector.java, someCollector.java, everyCollector.java. in the directory.... (1 Reply)
Discussion started by: jason.bean
1 Replies

9. UNIX for Advanced & Expert Users

Access Awk Variables Outside Scope

Sorry in the wrong forum. Moving this to right forum. (2 Replies)
Discussion started by: Amruta Pitkar
2 Replies

10. UNIX for Dummies Questions & Answers

Need help to access/mount so to access folder/files on a Remote System using Linux OS

Hi I need to access files from a specific folder of a Linux system from an another Linux System Remotely. I know how to, Export a folder on One SCO System & can access the same by using Import via., NFS in the Sco Unix SVR4 System using the scoadmin utility. Also, I know to use mount -t ... (2 Replies)
Discussion started by: S.Vishwanath
2 Replies
Login or Register to Ask a Question