Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > how can i access value outside awk and how can i split string value of array

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-26-07, 16:18
jason.bean jason.bean is offline
Registered User
 
Join Date: Nov 2007
Posts: 1
how can i access value outside awk and how can i split string 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.

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]
}'

#echo $progexe # Not able to get value of progexe or array progexearr here
#java -classpath $CLASSPATH:. $progexe


OR i have used another approach which is.....


#!/bin/bash
source ~/.login
pruneclass=""
pruneclass="$(find myinfo/yourinfo/supplierinfo -name "*llector.java*")"
st=(echo "$pruneclass")
for (( j = 0 ; j <= ${#st[*]} ; j++ ))
{
#echo ${st[*]}
#echo "${st[$j]}"
#echo ${st[j]}

#javac ${st[$j]} # Here the string is myinfo/yourinfo/everyinfo/myCollector.java which is compiling absolutely fine
#java -classpath $CLASSPATH:. ${st[$j]}
# But here i want only substring "myCollector" in order to execute it. How do i split the string values of array to get the substring "myCollector".
}

Any help would be really appreciated. I am trying it for 3 days and not yet successful.
Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 11-28-07, 11:12
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 2,227
Check the basename command.
__________________
===
Nick Ivanov
Freelance database consultant
www.datori.org
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On