bug-textutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unix Utilities CUT


From: Bill Cecchin
Subject: Re: Unix Utilities CUT
Date: Sat Nov 9 12:20:01 2002

There is the crux of my problem.  I used the cut command as you show below,
on a text file and got the following results.

C:\bill\bill\data>cut -d ` ` -f 2 test_spaces.txt
cut: `: No such file or directory
1 Northing Easting
2 0705748 4353137
3 0705285 4353570
4 0705156 4353526
5 0704775 4353069

The file  test_spaces.txt  of course looks like:

C:\bill\bill\data>head -5 test_spaces.txt
1 Northing Easting
2 0705748 4353137
3 0705285 4353570
4 0705156 4353526
5 0704775 4353069

Please NOTE that I have tried  cut  using: a  ' single apostraphe,  a `
guave,   and with and without spaces
around each argument, and have never gotten anything but a listing of the
complete file.

On our  IBM-AIX Unix servers I use the exact same file and basically the
same command, but get what I need::

/wcecchin: cut -d ' ' -f2 test_spaces.txt
Northing
0705748
0705285
0705156
0704775

So, I figured it must be some kind of 'bug' in the Windows 2000 version of
GNU Utilities.  I do thank you for your
response and helping me work this out.  Thank you.     SmileS

Bill Cecchin - GIS
USDA-FS Tahoe National Forest
E-Mail:   address@hidden
Phone: 530-478-6247   Fax: 530-478-6109




                                                                                
                  
                    address@hidden                                              
                   
                    m (Bob               To:     Bill Cecchin <address@hidden>  
              
                    Proulx)              cc:     address@hidden                 
           
                                         Subject:     Unix Utilities  CUT       
                  
                    11/07/2002                                                  
                  
                    10:26 AM                                                    
                  
                                                                                
                  
                                                                                
                  




Bill Cecchin <address@hidden> [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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]