Access value outside awk or split value of array


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Access value outside awk or split value of array
# 1  
Old 11-26-2007
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.

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.
# 2  
Old 11-26-2007
#java -classpath $CLASSPATH:. ${st[$j]}

try
java -classpath $CLASSPATH:. $(basename ${st[$j]} .java)

basename will strip directory names and the extension You specify in the second argument.
See also dirname command.

/Lakris
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to split the string value to an array?

Test1.txt Tom is hot Test.sh filename="/directory/Test1.txt" set - A store while IFS= read value do awk '{split($value,store," ")}' done < "$filename" echo ${#sore} From the code in the executing file, I would like each... (8 Replies)
Discussion started by: TestKing
8 Replies

2. UNIX for Beginners Questions & Answers

How to split a string into array?

value=malayalam # i need to store the value in an array by splitting the character #the output i need is m a l a y a l a m Please use CODE tags for output data as well as required by forum rules! (5 Replies)
Discussion started by: Meeran Rizvi
5 Replies

3. Shell Programming and Scripting

Perl split and array

Hello, I have the following code: while ($line = <fd_in>) { 126 $line = " " . $line ; 127 print "our_line:$line\n"; 128 @list = split (/\s+/, $line) ; 129 print "after_split:@list\n"; 130 print "$list\t$list\t$list\t$list\t$list\t$list$list\t\n"; 131 $len =... (2 Replies)
Discussion started by: Zam_1234
2 Replies

4. 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

5. Shell Programming and Scripting

Split the file and access that files through array and loop

Hi All, the below is my requirement.. i need to split the file based on line and put that files in a array and need to access that files through loop finally i should send the files through mail.. how can we achieve this ..I am new to shell script please guide me.. I am using KSH.. ... (11 Replies)
Discussion started by: kalidoss
11 Replies

6. Shell Programming and Scripting

awk to split one field and print the last two fields within the split part.

Hello; I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies

7. Shell Programming and Scripting

split and making an array inside another array

I want to run an awk split on a value that has been pushed through an array and I was wondering what the syntax should be?? e.g. running time strings through an array and trying to examine just minutes: 12:25:30 10:15:13 08:55:23 awk ' NR==FNR{ ... (2 Replies)
Discussion started by: dcfargo
2 Replies

8. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

9. Shell Programming and Scripting

How to get array to not split at spaces?

I have been working on some code for a while, that will parse a log file, look for a specified time discrepancy between entries, and then print that line +/- n other lines out to a file... #!/bin/bash file=$1 # The input log file maxTime=$2 # The time discrepancy to look for n=$3 ... (1 Reply)
Discussion started by: jjinno
1 Replies

10. Shell Programming and Scripting

split to array in perl

Collegues I have flat file in the following format. 137 (NNP Kerala) (NNP India) 92 (NN Rent) (NN Range) 70 (NNP Thiruvananthapuram) (NNP Kerala) 43 (NNP Tourist) (NNP Home) 40 (NNP Reserve) (NNP Now) 25 (SYM @) (NN hotelskerala) 25 (NNP Thiruvananthapuram-695001) (NNP Kerala) 23 (NN... (3 Replies)
Discussion started by: jaganadh
3 Replies
Login or Register to Ask a Question