Reputation: 1235
I have a text file in which I must cut the fields 3,4,5 and 8:
219 432 4567 Harrison Joel M 4540 Accountant 09-12-1985
219 433 4587 Mitchell Barbara C 4541 Admin Asst 12-14-1995
219 433 3589 Olson Timothy H 4544 Supervisor 06-30-1983
219 433 4591 Moore Sarah H 4500 Dept Manager 08-01-1978
219 431 4527 Polk John S 4520 Accountant 09-22-1998
219 432 4567 Harrison Joel M 4540 Accountant 09-12-1985
219 432 1557 Harrison James M 4544 Supervisor 01-07-2000
Since the delimiter by default is tab the command to extract the fields would be:
cut -f 3,4,5,8 filename
The thing is that the output is the same as the original file content. What is happening here? Why doesn't this work?
Upvotes: 1
Views: 5698
Reputation: 9980
Your file doesn't actually contain any tab characters.
By default, cut
prints any lines which don't contain the delimiter, unless you specify the -s
option.
Since your records are aligned on character boundaries rather than tab-separated, you should use the -c
option to specify which columns to cut. For example:
cut -c 9-12,14-25,43-57 file
Upvotes: 3