Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!att!cbnewse!fredriks From: fredriks@cbnewse.ATT.COM (lars.fredriksen) Newsgroups: comp.os.minix Subject: RE: cut Message-ID: <12544@cbnewse.ATT.COM> Date: 12 Jan 90 16:21:52 GMT Reply-To: fredriks@cbnewse.ATT.COM (lars.fredriksen,ih,) Organization: AT&T Bell Laboratories Lines: 68 Hi! I tried to extract columns from a file, just as ast tried to do with cut, but I used the shell. Correct me if I am wrong, but it would seem to me that the following should work: while read COL1 COL2 COL3 ; do echo $COL2 $COL3 done Let say the script is called "extract", then you could do extract < listing > output or whatever you want to do.. The only hitch with this scheme is that the shell is broken. The documentation on the Bourne shell says that read reads a line from stdin, then assigning the first word to the first variable, second word to the second variable,.. rest of the line to the last variable. That means that if the listing file in the above example contained: 011090 45000 cu.c COL1 should be equal to 011090, COL2 = 45000, and COL3 = cu.c. With the minix shell this is what you get: COL1 = 011090, COL2 = " ", COL3 = 45000. We could work around this by using variables for the spaces too. That holds true for a file that has the same number of spaces between each column, but not if the file looks like the one following: 011090 4500 cu.c 011190 500 temp.out 011290 0 empty.out It is even possible to handle this, but it becomes a mess in a hurry. Another thing that the shell seems to do wrong(This has probably been pointed out already) is the following: FILES=`/bin/ls *.c` for i in $FILES ; do echo $i done The shell varible dosn't have the right format for this to work. If my memory server me right, only the last file will be echoed. I haven't tested this under 1.5.0 yet. PS. In regards to system V's version of cut; here is an extract from the man pages: -d char The character following -d is the field delimiter (-f option only). Default if tab. Space or other characters with special meaning to the shell must be quoted. -flist The list following -f is a list of fileds assumed to be separated by the delimiter character specified by the -d option;e.q., -f1,7 copies the first and seventh field only. Sincerely Lars Fredriksen