-Hi, I have a problem with parcing/spliting a file record into two parts and assigning the split parts to two viriables. The record is as follows:
ftrn facc ttrd feed xref fsdb fcp ruldb csdb omom fordr ftxn fodb fsdc texc oxox reng ttrn ttxn fqdb fcsh foma fcl1 fcl2 fnav tgdb aqdb hfps hfui hfpu hfdb psqport uiqport twgs cedb seng grui grag hflm lmqport
The colomns are separated by few spaces. I need to assign coloms 1 thru 31 to one variable and the rest to another variable. The spacing btw the colomns should be kept intact. Any ideas? Thanks a lot for help.
tmp="ftrn facc ttrd feed xref fsdb fcp ruldb csdb omom fordr ftxn fodb fsdc texc oxox reng ttrn ttxn fqdb fcsh foma fcl1 fcl2 fnav tgdb aqdb hfps hfui hfpu hfdb psqport uiqport twgs cedb seng grui grag hflm lmqport"
tmp1=$(echo $tmp | cut -d" " -f1-31)
$ echo $tmp1
ftrn facc ttrd feed xref fsdb fcp ruldb csdb omom fordr ftxn fodb fsdc texc oxox reng ttrn ttxn fqdb fcsh foma fcl1 fcl2 fnav tgdb aqdb hfps hfui hfpu hfdb
tmp2=$(echo $tmp | cut -d" " -f32-)
$ echo $tmp2
psqport uiqport twgs cedb seng grui grag hflm lmqport
era
May 20, 2008, 7:47am
3
If there are multiple spaces which should be preserved, you need to double-quote all variables.
Thanks a lot. It worked great!!
Era, you are right, unfortunatelly the spacing is not preserved. Can you please give me the example of how to preserve spacing between colomns. Thanks
Era, can you plz give me the example, I am struggling with preserving the correct spacing. Thanks a lot for help and advice -Andrew