Guest_imported
New member
- Jan 1, 1970
- 0
Help! I want to do something like the following. I want to be able to read certain fields of a file using awk and print them out using a formatted print statement. However, the part I'm struggling with is I want to use what is in field 2 of the file and then print the array element that matches that field. For example, if the second field of the first line of file temp2 was equal to 10, then I want to print the array variable dsa[10] instead of the actual field. Is this possible?? The stuff below does not work but I included for clarification. There are some workarounds such as reading in the file one line at a time but that is very very slow when dealing with hundreds of thousands of lines. Any help would be greatly appreciated.
Thanks,
KBH
# Script1 below
integer n=1
integer dsatype
while read dsa[n]
do
n=n+1
done < dsa.file
awk '{printf("%43s %14s %10s %10s\n", ${dsa[$2]},$3,$4,$5)}' temp2 > temp3
Thanks,
KBH
# Script1 below
integer n=1
integer dsatype
while read dsa[n]
do
n=n+1
done < dsa.file
awk '{printf("%43s %14s %10s %10s\n", ${dsa[$2]},$3,$4,$5)}' temp2 > temp3