Feel up for a awk/ksh question?
I'm trying to get data into a ksh while loop using ksh arrays. This I've found is more efficient than for-item-in-list construct.
The problem is my array elements are descriptions which have spaces between the words. My descriptions are in the 2nd field of a CSV file:
CSV file:
[tt]c1,Tank Level Controller
f1,Flow Path #1
f2,Flow Path #2
h1,Header #1
h2,Header #2
m1,Motor #1
m2,Motor #2
p1,Pump #1
p2,Pump #2
t1,Tank #1
v1,Valve #1
v2,Valve #2[/tt]
The script:
The result is:
[tt]</OBJ_DESC>ank Level Controller
</OBJ_DESC>low Path #1
</OBJ_DESC>low Path #2
</OBJ_DESC>eader #1
</OBJ_DESC>eader #2
</OBJ_DESC>otor #1
</OBJ_DESC>otor #2
</OBJ_DESC>ump #1
</OBJ_DESC>ump #2
</OBJ_DESC>ank #1
</OBJ_DESC>alve #1
</OBJ_DESC>alve #2[/tt]
I get the similar result if I use XXXXX for <OBJ_DESC> and YYYYY for </OBJ_DESC>.
For example:
[tt]YYYYYank Level Controller[/tt]
Any ideas?
CraigMan >
:O>
I'm trying to get data into a ksh while loop using ksh arrays. This I've found is more efficient than for-item-in-list construct.
The problem is my array elements are descriptions which have spaces between the words. My descriptions are in the 2nd field of a CSV file:
CSV file:
[tt]c1,Tank Level Controller
f1,Flow Path #1
f2,Flow Path #2
h1,Header #1
h2,Header #2
m1,Motor #1
m2,Motor #2
p1,Pump #1
p2,Pump #2
t1,Tank #1
v1,Valve #1
v2,Valve #2[/tt]
The script:
Code:
#!/usr/bin/ksh
# set IFS to NEWLINE only (ignore SPACES and TABS)
IFS"
"
set -A array1 $(gawk 'BEGIN {FS=","} {print $2}' file.csv)
i=0
while (( $i<${#array1[*]} ))
do
print "<OBJ_DESC>${array1[$i]}</OBJ_DESC>"
i=$((${i}+1))
done
The result is:
[tt]</OBJ_DESC>ank Level Controller
</OBJ_DESC>low Path #1
</OBJ_DESC>low Path #2
</OBJ_DESC>eader #1
</OBJ_DESC>eader #2
</OBJ_DESC>otor #1
</OBJ_DESC>otor #2
</OBJ_DESC>ump #1
</OBJ_DESC>ump #2
</OBJ_DESC>ank #1
</OBJ_DESC>alve #1
</OBJ_DESC>alve #2[/tt]
I get the similar result if I use XXXXX for <OBJ_DESC> and YYYYY for </OBJ_DESC>.
For example:
[tt]YYYYYank Level Controller[/tt]
Any ideas?
CraigMan >