| | |
how to access variable outside awk and spliting the string in array
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 0
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.
OR i have used another approach which is.....
Any help would be really appreciated. I am trying it for 3 days and not yet successful.
Thanks in advance.
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)
#!/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) [inline] # Please dont worry about the above code [/inline] progexearr[i]=progexe print progexe [inline] # i am getting myCollector, yourCollector,someCollector and everyCollector. How can i access the value of variable and array outside awk. [/inline] print progexearr[i] }' #echo $progexe [inline] # Not able to get value of progexe or array progexearr here [/inline] #java -classpath $CLASSPATH:. $progexe
OR i have used another approach which is.....
Shell Scripting Syntax (Toggle Plain Text)
#!/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]} [inline] # Here the string is myinfo/yourinfo/everyinfo/myCollector.java which is compiling absolutely fine [/inline] #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] }
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.
If I understand correctly all you need is just:
Shell Scripting Syntax (Toggle Plain Text)
for prog in /myinfo/yourinfo/supplierinfo/*Collector.java;do progname="${prog##*/}" java -classpath "$CLASSPATH:." "${progname%.java}" done
Last edited by radoulov; Nov 26th, 2007 at 5:00 pm.
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 0
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
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.
Strange,
what is the output of the following block on your system, here's mine:
what is the output of the following block on your system, here's mine:
Shell Scripting Syntax (Toggle Plain Text)
$ ls -l myinfo/yourinfo/supplierinfo/*Collector.java -rw-r--r-- 1 radoulov radoulov 0 2007-11-27 09:48 myinfo/yourinfo/supplierinfo/everyCollector.java -rw-r--r-- 1 radoulov radoulov 0 2007-11-27 09:48 myinfo/yourinfo/supplierinfo/myCollector.java -rw-r--r-- 1 radoulov radoulov 0 2007-11-27 09:48 myinfo/yourinfo/supplierinfo/someCollector.java -rw-r--r-- 1 radoulov radoulov 0 2007-11-27 09:48 myinfo/yourinfo/supplierinfo/yourCollector.java $ for prog in myinfo/yourinfo/supplierinfo/*Collector.java;do > progname="${prog##*/}" > echo "Your command will run this: > java -classpath "$CLASSPATH:." "${progname%.java}"" > done Your command will run this: java -classpath :. everyCollector Your command will run this: java -classpath :. myCollector Your command will run this: java -classpath :. someCollector Your command will run this: java -classpath :. yourCollector
![]() |
Similar Threads
- I am needing a control array, but VB.NET doesn't support them... (VB.NET)
- string array (Java)
- How do I convert a vector to a String array ? (Java)
- Declaring string array, initializing later... (C++)
- Copy string into an array (C#)
- ArrayList to multi-dimensional string array (C#)
- How to access a variable of a diff class (C++)
- Geting elements from a String Array (C++)
Other Threads in the Shell Scripting Forum
- Previous Thread: how break from find / -wholename= 'somename'>>filename | tail --f filename
- Next Thread: reverse with cut command
| Thread Tools | Search this Thread |





