943,985 Members | Top Members by Rank

Ad:
Nov 26th, 2007
0

how to access variable outside awk and spliting the string in array

Expand Post »
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.
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. source ~/.login
  3. progexearr=""
  4. pruneclass=""
  5. pruneclass="$(find myinfo/yourinfo/supplierinfo -name "*llector.java*")"
  6.  
  7. echo "$pruneclass"| awk '{
  8. z=split($0,flds," ")
  9. for(i=1;i<=z;i++)
  10. progcompile=flds[i]
  11. p2 = length(progcompile)
  12. exetemp=substr(progcompile,41,p2)
  13. progexe=substr(exetemp,0,length(exetemp)-5) [inline] # Please dont worry about the above code [/inline]
  14. progexearr[i]=progexe
  15. print progexe [inline] # i am getting myCollector, yourCollector,someCollector and everyCollector. How can i access the value of variable and array outside awk. [/inline]
  16. print progexearr[i]
  17. }'
  18.  
  19. #echo $progexe [inline] # Not able to get value of progexe or array progexearr here [/inline]
  20. #java -classpath $CLASSPATH:. $progexe



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

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. source ~/.login
  3. pruneclass=""
  4. pruneclass="$(find myinfo/yourinfo/supplierinfo -name "*llector.java*")"
  5. st=(echo "$pruneclass")
  6. for (( j = 0 ; j <= ${#st[*]} ; j++ ))
  7. {
  8. #echo ${st[*]}
  9. #echo "${st[$j]}"
  10. #echo ${st[j]}
  11.  
  12. #javac ${st[$j]} [inline] # Here the string is myinfo/yourinfo/everyinfo/myCollector.java which is compiling absolutely fine [/inline]
  13. #java -classpath $CLASSPATH:. ${st[$j]} [inline] # 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". [/inline]
  14. }

Any help would be really appreciated. I am trying it for 3 days and not yet successful.
Thanks in advance.
Last edited by jason.bean; Nov 26th, 2007 at 3:53 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jason.bean is offline Offline
2 posts
since Nov 2007
Nov 26th, 2007
0

Re: how to access variable outside awk and spliting the string in array

If I understand correctly all you need is just:

Shell Scripting Syntax (Toggle Plain Text)
  1. for prog in /myinfo/yourinfo/supplierinfo/*Collector.java;do
  2. progname="${prog##*/}"
  3. java -classpath "$CLASSPATH:." "${progname%.java}"
  4. done
Last edited by radoulov; Nov 26th, 2007 at 5:00 pm.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
radoulov is offline Offline
54 posts
since Feb 2007
Nov 26th, 2007
0

Re: how to access variable outside awk and spliting the string in array

sorry sir, its not working

actually while executing the java program we need only program name without .java extension

i.e. java myCollector #No .java as extension

that is the reason that i am trying to split the string either using awk or spliting string in array

but a great thanks radoulov...for taking interest to help me
Last edited by jason.bean; Nov 26th, 2007 at 11:47 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jason.bean is offline Offline
2 posts
since Nov 2007
Nov 27th, 2007
0

Re: how to access variable outside awk and spliting the string in array

Strange,
what is the output of the following block on your system, here's mine:

Shell Scripting Syntax (Toggle Plain Text)
  1. $ ls -l myinfo/yourinfo/supplierinfo/*Collector.java
  2. -rw-r--r-- 1 radoulov radoulov 0 2007-11-27 09:48 myinfo/yourinfo/supplierinfo/everyCollector.java
  3. -rw-r--r-- 1 radoulov radoulov 0 2007-11-27 09:48 myinfo/yourinfo/supplierinfo/myCollector.java
  4. -rw-r--r-- 1 radoulov radoulov 0 2007-11-27 09:48 myinfo/yourinfo/supplierinfo/someCollector.java
  5. -rw-r--r-- 1 radoulov radoulov 0 2007-11-27 09:48 myinfo/yourinfo/supplierinfo/yourCollector.java
  6. $ for prog in myinfo/yourinfo/supplierinfo/*Collector.java;do
  7. > progname="${prog##*/}"
  8. > echo "Your command will run this:
  9. > java -classpath "$CLASSPATH:." "${progname%.java}""
  10. > done
  11. Your command will run this:
  12. java -classpath :. everyCollector
  13. Your command will run this:
  14. java -classpath :. myCollector
  15. Your command will run this:
  16. java -classpath :. someCollector
  17. Your command will run this:
  18. java -classpath :. yourCollector
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
radoulov is offline Offline
54 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: how break from find / -wholename= 'somename'>>filename | tail --f filename
Next Thread in Shell Scripting Forum Timeline: reverse with cut command





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC