Operating System - HP-UX
1833685 Members
3789 Online
110062 Solutions
New Discussion

ksh help: extracts fields of each line to different variables.

 
SOLVED
Go to solution
Hanry Zhou
Super Advisor

ksh help: extracts fields of each line to different variables.

I have a file, and consists of a number of lines. Each line has 3 fields separated by space. Now I want to have a loop, and assign these 3 files to each different variables. how do I do that using ksh?
Thanks,
none
3 REPLIES 3
curt larson_1
Honored Contributor
Solution

Re: ksh help: extracts fields of each line to different variables.

not to sure what your asking, but here is a start and we can work from that

cat $yourfile |
while read var1 var2 var3 rest
do
print "var1 = $var1"
print "var2 = $var2"
print "var3 = $var3"
done
David Child_1
Honored Contributor

Re: ksh help: extracts fields of each line to different variables.

I'm not exactly sure if this is what you need, but perhaps this might work;

cat myfile | while read field0 field1 field2
do
echo "Field1: $field0"
echo "Field2: $field1"
echo "Field3: $field2"
done

Just a quick something to see if is the results you are looking for.

David
David Child_1
Honored Contributor

Re: ksh help: extracts fields of each line to different variables.

Sorry, I got busy and didn't check back before I finished my reply. Curt already gave you the same solution. No points for me please.

David