Bill Cecchin <[EMAIL PROTECTED]> [2002-11-01 10:27:37 -0800]: > I am not sure if this is a bug or just lack of knowledge on my part. In > Unix I could always use 'cut' to pull the needed fields out of our text > files. In GNU Utilities I can't find any combination of parameters that > will allow using 'cut' on a file delimited by spaces. Is it possible to > cut a file using a SPACE as a delimiter between fields?
The cut program is a very old program and on all unixlike systems of which I am aware the default field delimiter is a TAB. The original use of the program was for tabular data in data files which had fields separated by TABs. You can set the field delimiter to be anything you want using the -d option. That is a standard option and should work on all unixlike systems. cut -d ' ' -f 2 But the behavior is such that this is probably not what you want to do. The cut program will treat a leading space as an empty field by definition. The field numbers are different if there are leading spaces or not. This is not a bug but part of the definition and use of the cut command. Therefore awk is really a better choice for most free form data that you just want to pull out fields. Using cut you can see that it is sensitive to field separators. Although the use it is put to will define this. It all depends on what you want. echo one two three | cut -d ' ' -f 2 two echo "one two three" | cut -d ' ' -f 2 two echo " one two three" | cut -d ' ' -f 2 one Using awk most people find this result more intuitive. echo one two three | awk '{print $2}' two echo "one two three" | awk '{print $2}' two echo " one two three" | awk '{print $2}' two Bob _______________________________________________ Bug-textutils mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-textutils