bug-coreutils
[Top][All Lists]
Advanced

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

Re: [ADD TO FAQ] : cut : using space as input delimiter


From: seb_kramm
Subject: Re: [ADD TO FAQ] : cut : using space as input delimiter
Date: Wed, 12 Mar 2008 15:55:32 +0100
User-agent: Thunderbird 2.0.0.12 (Windows/20080213)

Hello, thanks for your response,

Bob Proulx a écrit :
seb_kramm wrote:
I have search about an hour on how to tell 'cut' to use space as input delimiter, finally found out alone ! Below is the question I was about to post, and the solution. I suggest adding this "trick" to the FAQ, or even to the manual.

I will add something to the FAQ since this has come up a few times.

Thanks for the future users

I have a generated numeric data file, to be plotted using gnuplot. The fields are separated with spaces. Before plotting, I need to do some basic line/text processing, using 'cut' and 'join'.

'cut' isn't the best tool to cut fields.  'awk' is better.

Yes, even though I am a windows user ;-), I heard about awk, but I needed something quick, and didn't want to spent time on learning the syntax. My needs seemed simple. But I'll take a look at awk for sure as soon as I have some time.

# data
1  1.1  1.3  1.4
2  1.2  1.5  1.6
...

Unfortunatly, I can't manage to use the space character as input separator for 'cut'. I read the coreutils FAQ, the manual (5.3.0), p.43, but I understand (and tried) that this is not possible.

The problem is that the fields are separated by TWO spaces not one
space.  This means that in the above there are SEVEN fields not four.
Field 2 that you want to cut is an empty field.  You would want field
3 instead.

Ah. Is that a problem ? I mean, when I talk about the space character as a field-separator, to me, it's the same if there is 1 or 2 or more spaces. Like in a source code, it doesn't matter how much spaces or tabs there are.

Quote the whole 'd' option:

Yes.  Or quote just the delimiter.  Either way is exactly the same to
[...]

Another solution is using 'unexpand' to replace spaces by tabs

Yes.  'cut' was really designed to work on TAB separated fields.
Using 'unexpand' to get to TAB separated fields is in the spirit of
the way cut is designed to work.  Today if 'cut' were designed again
it would probably be using a comma by default because .csv files are
more common today than TAB separate fields.  I would be inclined to go
this way because then things are more obvious because the delimiters
are visible.

I agree, the only reason I used space as a delimitor is that it is the default separator for gnuplot, and that I was to lazy to find the command to tell it to use another separator. But I really better like .csv style.

Sebastien Kramm






reply via email to

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