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

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 2
Reputation: jason.bean is an unknown quantity at this point 
Solved Threads: 0
jason.bean jason.bean is offline Offline
Newbie Poster

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

 
0
  #1
Nov 26th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 54
Reputation: radoulov is an unknown quantity at this point 
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

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

 
0
  #2
Nov 26th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: jason.bean is an unknown quantity at this point 
Solved Threads: 0
jason.bean jason.bean is offline Offline
Newbie Poster

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

 
0
  #3
Nov 26th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 54
Reputation: radoulov is an unknown quantity at this point 
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

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

 
0
  #4
Nov 27th, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC