Strake | 1 Aug 2012 06:07
Picon

[PATCH] sbase: add cut

Will now need libutf.

diff -r 8cf300476909 Makefile
--- a/Makefile	Sat Jun 09 18:53:39 2012 +0100
+++ b/Makefile	Tue Jul 31 23:06:28 2012 -0500
 <at>  <at>  -27,6 +27,7  <at>  <at> 
 	cksum.c    \
 	cmp.c      \
 	cp.c       \
+	cut.c      \
 	date.c     \
 	dirname.c  \
 	echo.c     \
diff -r 8cf300476909 config.mk
--- a/config.mk	Sat Jun 09 18:53:39 2012 +0100
+++ b/config.mk	Tue Jul 31 23:06:28 2012 -0500
 <at>  <at>  -10,7 +10,7  <at>  <at> 
 LD = $(CC)
 CPPFLAGS = -D_POSIX_C_SOURCE=200112L
 CFLAGS   = -g -ansi -Wall -pedantic $(CPPFLAGS)
-LDFLAGS  = -g
+LDFLAGS  = -g -lutf

 #CC = tcc
 #LD = $(CC)
diff -r 8cf300476909 cut.1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cut.1	Tue Jul 31 23:06:28 2012 -0500
 <at>  <at>  -0,0 +1,51  <at>  <at> 
+.TH CUT 1
(Continue reading)

Uriel | 1 Aug 2012 14:36

Re: [PATCH] sbase: add cut

Use awk.

On Wed, Aug 1, 2012 at 6:07 AM, Strake <strake888 <at> gmail.com> wrote:
> Will now need libutf.
>
> diff -r 8cf300476909 Makefile
> --- a/Makefile  Sat Jun 09 18:53:39 2012 +0100
> +++ b/Makefile  Tue Jul 31 23:06:28 2012 -0500
>  <at>  <at>  -27,6 +27,7  <at>  <at> 
>         cksum.c    \
>         cmp.c      \
>         cp.c       \
> +       cut.c      \
>         date.c     \
>         dirname.c  \
>         echo.c     \
> diff -r 8cf300476909 config.mk
> --- a/config.mk Sat Jun 09 18:53:39 2012 +0100
> +++ b/config.mk Tue Jul 31 23:06:28 2012 -0500
>  <at>  <at>  -10,7 +10,7  <at>  <at> 
>  LD = $(CC)
>  CPPFLAGS = -D_POSIX_C_SOURCE=200112L
>  CFLAGS   = -g -ansi -Wall -pedantic $(CPPFLAGS)
> -LDFLAGS  = -g
> +LDFLAGS  = -g -lutf
>
>  #CC = tcc
>  #LD = $(CC)
> diff -r 8cf300476909 cut.1
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
(Continue reading)

Martin Kopta | 1 Aug 2012 14:54
Picon

Re: [PATCH] sbase: add cut

On 08/01/2012 02:36 PM, Uriel wrote:
> Use awk.

Use Perl.

Niki Yoshiuchi | 1 Aug 2012 14:58
Picon
Gravatar

Re: [PATCH] sbase: add cut

Why would you use awk or Perl when you have the best programming language available: Ruby?

On Aug 1, 2012 8:55 AM, "Martin Kopta" <martin <at> kopta.eu> wrote:
On 08/01/2012 02:36 PM, Uriel wrote:
Use awk.

Use Perl.


Kurt H Maier | 1 Aug 2012 15:09
Picon
Favicon

Re: [PATCH] sbase: add cut

On Wed, Aug 01, 2012 at 08:58:00AM -0400, Niki Yoshiuchi wrote:
> Why would you use awk or Perl when you have the best programming language
> available: Ruby?
> On Aug 1, 2012 8:55 AM, "Martin Kopta" <martin <at> kopta.eu> wrote:
> 
> > On 08/01/2012 02:36 PM, Uriel wrote:
> >
> >> Use awk.
> >>
> >
> > Use Perl.
> >
> >
> >

I hereby declare this mail thread a disaster area of top-posting and
language fanboyism and request immediate dispatch of the vans.

Also, I'm really curious why people use cut when awk exists.

Martin Kopta | 1 Aug 2012 15:18
Picon

Re: [PATCH] sbase: add cut

On 08/01/2012 03:09 PM, Kurt H Maier wrote:
> On Wed, Aug 01, 2012 at 08:58:00AM -0400, Niki Yoshiuchi wrote:
>> Why would you use awk or Perl when you have the best programming language
>> available: Ruby?
>> On Aug 1, 2012 8:55 AM, "Martin Kopta" <martin <at> kopta.eu> wrote:
>>
>>> On 08/01/2012 02:36 PM, Uriel wrote:
>>>
>>>> Use awk.
>>>>
>>>
>>> Use Perl.
>>>
>>>
>>>
>
> I hereby declare this mail thread a disaster area of top-posting and
> language fanboyism and request immediate dispatch of the vans.
>
> Also, I'm really curious why people use cut when awk exists.

$ du -b /usr/bin/cut /usr/bin/gawk /opt/plan9/bin/awk
38600   /usr/bin/cut
400212  /usr/bin/gawk
105700  /opt/plan9/bin/awk

Speed and simplicity I guess?

Why would I use awk of which I don't remember syntax, when I could often 
do with trustworthy cut easily? Seriously, apart from '{print $1}' and 
doing sums and stuff, I don't know awk. I don't want to. It is weird 
intermezzo between simple cut/sed/.. and almighty perl. Never understood 
awk users.

Strake | 1 Aug 2012 15:32
Picon

Re: [PATCH] sbase: add cut

On 01/08/2012, Martin Kopta <martin <at> kopta.eu> wrote:
>> Also, I'm really curious why people use cut when awk exists.
>
> $ du -b /usr/bin/cut /usr/bin/gawk /opt/plan9/bin/awk
> 38600   /usr/bin/cut
> 400212  /usr/bin/gawk
> 105700  /opt/plan9/bin/awk
>
> Speed and simplicity I guess?
>
> Why would I use awk of which I don't remember syntax, when I could often
> do with trustworthy cut easily?

This. Actually just simplicity; I'm not sure which has better speed.

Meh.

Strake | 1 Aug 2012 15:48
Picon

Re: [PATCH] sbase: add cut

I rewrote cut cleaner, but am not sure whether I ought to bother to
send it, if ye would rather keep sbase sans cut.

Ryan Mullen | 1 Aug 2012 16:04
Picon

Re: [PATCH] sbase: add cut

HI,

On Wed, Aug 1, 2012 at 9:48 AM, Strake <strake888 <at> gmail.com> wrote:
> I rewrote cut cleaner, but am not sure whether I ought to bother to
> send it, if ye would rather keep sbase sans cut.

IMO cut is a good tool to include. I use cut's functionality much more
than awk's; it's a simpler tool that does a basic thing and many
scripts use it.

Exclusion of cut would make sbase not viable when existing scripts
need to be supported.

Ryan

Nick | 1 Aug 2012 16:21
Picon
Favicon

Re: [PATCH] sbase: add cut

Quoth Ryan Mullen:
> Exclusion of cut would make sbase not viable when existing scripts
> need to be supported.

Exactly. I only use awk to do these kind of jobs nowadays, but cut 
is in use a lot of places, so it makes sense to use it. And it can 
be easier for certain kinds of jobs (e.g. printing all fields but 
the first.)

pancake | 1 Aug 2012 16:23

Re: [PATCH] sbase: add cut

The only thing i miss in cut is mutichar word split. Which is properly handled by awk. For example:

If a line is splitted by multiple spaces or a mix of tabs and spaces it is not handled right by cut. But awk does
the job.

That's quite anoying because of the crappy output of many tools that abuse whitespaces and other human
inhabilities to identify chars in empty places.

On Aug 1, 2012, at 16:04, Ryan Mullen <rmmullen <at> gmail.com> wrote:

> HI,
> 
> On Wed, Aug 1, 2012 at 9:48 AM, Strake <strake888 <at> gmail.com> wrote:
>> I rewrote cut cleaner, but am not sure whether I ought to bother to
>> send it, if ye would rather keep sbase sans cut.
> 
> IMO cut is a good tool to include. I use cut's functionality much more
> than awk's; it's a simpler tool that does a basic thing and many
> scripts use it.
> 
> Exclusion of cut would make sbase not viable when existing scripts
> need to be supported.
> 
> Ryan
> 

Ryan Mullen | 1 Aug 2012 16:29
Picon

Re: [PATCH] sbase: add cut

Hi,

On Wed, Aug 1, 2012 at 10:23 AM, pancake <pancake <at> youterm.com> wrote:
> The only thing i miss in cut is mutichar word split. Which is properly handled by awk. For example:
>
> If a line is splitted by multiple spaces or a mix of tabs and spaces it is not handled right by cut. But awk does
the job.

This is something that can be fixed with a pipe through tr before your
pipe through cut. Use tr to squeeze the multiple spaces down to a
single one or translate the spaces/tabs into whichever whitespace you
prefer.

hiro | 1 Aug 2012 16:33
Picon

Re: [PATCH] sbase: add cut

sometimes I only respond to the suckless becaus I want to annoy you
with my top-posts, although I have nothing to say whatsoever.

On 8/1/12, Ryan Mullen <rmmullen <at> gmail.com> wrote:
> Hi,
>
> On Wed, Aug 1, 2012 at 10:23 AM, pancake <pancake <at> youterm.com> wrote:
>> The only thing i miss in cut is mutichar word split. Which is properly
>> handled by awk. For example:
>>
>> If a line is splitted by multiple spaces or a mix of tabs and spaces it is
>> not handled right by cut. But awk does the job.
>
> This is something that can be fixed with a pipe through tr before your
> pipe through cut. Use tr to squeeze the multiple spaces down to a
> single one or translate the spaces/tabs into whichever whitespace you
> prefer.
>
>

Uriel | 1 Aug 2012 22:09

Re: [PATCH] sbase: add cut

On Wed, Aug 1, 2012 at 4:04 PM, Ryan Mullen <rmmullen <at> gmail.com> wrote:
>
> Exclusion of cut would make sbase not viable when existing scripts
> need to be supported.

Exclusion of bash would make sbase not viable when existing scripts
need to be supported.

What a lame argument.

Uriel

Nick | 2 Aug 2012 00:02
Picon
Favicon

Re: [PATCH] sbase: add cut

Quoth Uriel:
> On Wed, Aug 1, 2012 at 4:04 PM, Ryan Mullen <rmmullen <at> gmail.com> wrote:
> >
> > Exclusion of cut would make sbase not viable when existing scripts
> > need to be supported.
> 
> Exclusion of bash would make sbase not viable when existing scripts
> need to be supported.
> 
> What a lame argument.

Bah. There's a balance to be struck. Scripts which aren't awful 
should be supported. The issue is whether using cut constitutes 
'awful'. I think it does not. There are legitimate cases where it's 
simpler and clearer than awk/sed.

Love from Nick.

Kurt H Maier | 2 Aug 2012 00:54
Picon
Favicon

Re: [PATCH] sbase: add cut

On Wed, Aug 01, 2012 at 11:02:52PM +0100, Nick wrote:
> 
> Bah. There's a balance to be struck. Scripts which aren't awful 
> should be supported. The issue is whether using cut constitutes 
> 'awful'. I think it does not. There are legitimate cases where it's 
> simpler and clearer than awk/sed.
> 

The question is: since cut can be implemented IN awk, why should it get
a separate C binary?  Anyone nattering about performance in a shell
script is barking up the wrong tree.

hiro | 2 Aug 2012 01:01
Picon

Re: [PATCH] sbase: add cut

because suckless lol

On 8/2/12, Kurt H Maier <khm-suckless <at> intma.in> wrote:
> On Wed, Aug 01, 2012 at 11:02:52PM +0100, Nick wrote:
>>
>> Bah. There's a balance to be struck. Scripts which aren't awful
>> should be supported. The issue is whether using cut constitutes
>> 'awful'. I think it does not. There are legitimate cases where it's
>> simpler and clearer than awk/sed.
>>
>
> The question is: since cut can be implemented IN awk, why should it get
> a separate C binary?  Anyone nattering about performance in a shell
> script is barking up the wrong tree.
>
>

Steven Blatchford | 2 Aug 2012 01:13
Picon

Re: [PATCH] sbase: add cut

On 18:54 Wed 01 Aug, Kurt H Maier wrote:
>On Wed, Aug 01, 2012 at 11:02:52PM +0100, Nick wrote:
>> 
>> Bah. There's a balance to be struck. Scripts which aren't awful 
>> should be supported. The issue is whether using cut constitutes 
>> 'awful'. I think it does not. There are legitimate cases where it's 
>> simpler and clearer than awk/sed.
>> 
>
>The question is: since cut can be implemented IN awk, why should it get
>a separate C binary?  Anyone nattering about performance in a shell
>script is barking up the wrong tree.

Give this[0] a read and see what you think.

[0] http://awk.freeshell.org/RangeOfFields

Kurt H Maier | 2 Aug 2012 01:21
Picon
Favicon

Re: [PATCH] sbase: add cut

On Wed, Aug 01, 2012 at 07:13:57PM -0400, Steven Blatchford wrote:
> 
> Give this[0] a read and see what you think.
> 
> [0] http://awk.freeshell.org/RangeOfFields
> 

I think their suggestions are based on
 1) deciding to use a shitty version of awk, and 
 2) the idea that you should give a shit if someone who doesn't know awk
    is reading your script.

I don't understand why sbase should care about either of these things.

Steven Blatchford | 2 Aug 2012 01:28
Picon

Re: [PATCH] sbase: add cut

On 19:21 Wed 01 Aug, Kurt H Maier wrote:
>On Wed, Aug 01, 2012 at 07:13:57PM -0400, Steven Blatchford wrote:
>> 
>> Give this[0] a read and see what you think.
>> 
>> [0] http://awk.freeshell.org/RangeOfFields
>> 
>
>I think their suggestions are based on
> 1) deciding to use a shitty version of awk, and 
> 2) the idea that you should give a shit if someone who doesn't know awk
>    is reading your script.
>
>I don't understand why sbase should care about either of these things.

Hmm you didn't read it or didn't read it well.

What is your awk to print fields three and four with this input:

    'foo bar baz quz'

Kurt H Maier | 2 Aug 2012 01:52
Picon
Favicon

Re: [PATCH] sbase: add cut

On Wed, Aug 01, 2012 at 07:28:57PM -0400, Steven Blatchford wrote:
> 
> What is your awk to print fields three and four with this input:
> 
>     'foo bar baz quz'
> 

Depends on what output format I want.  Get to the point instead of
trying to set me up for failure; I don't have time for this shit

Steven Blatchford | 2 Aug 2012 04:49
Picon

Re: [PATCH] sbase: add cut

On 19:52 Wed 01 Aug, Kurt H Maier wrote:
>On Wed, Aug 01, 2012 at 07:28:57PM -0400, Steven Blatchford wrote:
>> 
>> What is your awk to print fields three and four with this input:
>> 
>>     'foo bar baz quz'
>> 
>
>Depends on what output format I want.  Get to the point instead of
>trying to set me up for failure; I don't have time for this shit

I wanted to know how you use awk to get the same output as 
"cut -d' ' -f3-"

Also what about "cut -d' ' -f1,3,9-" ?

sjferrara | 2 Aug 2012 05:12
Picon

Re: [PATCH] sbase: add cut

> On 19:52 Wed 01 Aug, Kurt H Maier wrote:
>>On Wed, Aug 01, 2012 at 07:28:57PM -0400, Steven Blatchford wrote:
>>> 
>>> What is your awk to print fields three and four with this input:
>>> 
>>>     'foo bar baz quz'
>>> 
>>
>>Depends on what output format I want.  Get to the point instead of
>>trying to set me up for failure; I don't have time for this shit
> 
> I wanted to know how you use awk to get the same output as 
> "cut -d' ' -f3-"

awk '{for (i=3; i<=NF; i++) printf "%s ", $i} END {print}'

> Also what about "cut -d' ' -f1,3,9-" ?

awk '{printf "%s %s ", 1, 3; for (i=9; i<=NF; i++) printf "%s ", $i} END {print}'

Steven Blatchford | 2 Aug 2012 05:53
Picon

Re: [PATCH] sbase: add cut

On 00:12 Thu 02 Aug, sjferrara <at> gmail.com wrote:
>> On 19:52 Wed 01 Aug, Kurt H Maier wrote:
>>>On Wed, Aug 01, 2012 at 07:28:57PM -0400, Steven Blatchford wrote:
>>>> 
>>>> What is your awk to print fields three and four with this input:
>>>> 
>>>>     'foo bar baz quz'
>>>> 
>>>
>>>Depends on what output format I want.  Get to the point instead of
>>>trying to set me up for failure; I don't have time for this shit
>> 
>> I wanted to know how you use awk to get the same output as 
>> "cut -d' ' -f3-"
>
>awk '{for (i=3; i<=NF; i++) printf "%s ", $i} END {print}'
>
>
>> Also what about "cut -d' ' -f1,3,9-" ?
>
>awk '{printf "%s %s ", 1, 3; for (i=9; i<=NF; i++) printf "%s ", $i} END {print}'
>
I think you mean '... END {printf "\n"}' but even with this you have a
trailing space.

Paul Onyschuk | 2 Aug 2012 13:08
Picon
Gravatar

Re: [PATCH] sbase: add cut

On Wed, 1 Aug 2012 22:49:05 -0400, Steven Blatchford wrote:
> 
> I wanted to know how you use awk to get the same output as 
> "cut -d' ' -f3-"
> 

This can be done on multiple ways in awk, here is one example (a bit
extreme):

awk '{$1=$2=""; $0=substr($0, 3)}1'

--

-- 
Paul Onyschuk

hiro | 2 Aug 2012 13:20
Picon

Re: [PATCH] sbase: add cut

why not a C-to-awk compiler?

Martin Kopta | 2 Aug 2012 13:31
Picon

Re: [PATCH] sbase: add cut

On 08/02/2012 01:20 PM, hiro wrote:
> why not a C-to-awk compiler?

Written in Perl. NOW we are finally getting somewhere.

Calvin Morrison | 2 Aug 2012 16:33
Picon
Gravatar

Re: [PATCH] sbase: add cut

On 2 August 2012 07:31, Martin Kopta <martin <at> kopta.eu> wrote:
> On 08/02/2012 01:20 PM, hiro wrote:
>>
>> why not a C-to-awk compiler?
>
>
> Written in Perl. NOW we are finally getting somewhere.
>
>

I think cut is exactly the kind of job that awk (or sed) can be good
for. It seems crazy not to use an existing tool that implements all
the functionality, that can be nicely bundled in a a script.

Calvin

Kurt H Maier | 2 Aug 2012 16:34
Picon
Favicon

Re: [PATCH] sbase: add cut

On Thu, Aug 02, 2012 at 10:33:19AM -0400, Calvin Morrison wrote:
> 
> I think cut is exactly the kind of job that awk (or sed) can be good
> for. It seems crazy not to use an existing tool that implements all
> the functionality, that can be nicely bundled in a a script.
> 

To be honest, I feel the same way about head(1) -- why bother
maintaining C when the tool is obviously a subset of another tool?

Martin Kopta | 2 Aug 2012 19:42
Picon

Re: [PATCH] sbase: add cut

On 08/02/2012 04:34 PM, Kurt H Maier wrote:
> On Thu, Aug 02, 2012 at 10:33:19AM -0400, Calvin Morrison wrote:
>>
>> I think cut is exactly the kind of job that awk (or sed) can be good
>> for. It seems crazy not to use an existing tool that implements all
>> the functionality, that can be nicely bundled in a a script.
>>
>
> To be honest, I feel the same way about head(1) -- why bother
> maintaining C when the tool is obviously a subset of another tool?

This is what happens.

http://perllinux.sourceforge.net/
"A Linux distribution where ALL programs are written in perl."

Jacob Todd | 3 Aug 2012 03:07
Picon

Re: [PATCH] sbase: add cut

Kill it with fire.

On Aug 2, 2012 1:42 PM, "Martin Kopta" <martin <at> kopta.eu> wrote:
On 08/02/2012 04:34 PM, Kurt H Maier wrote:
On Thu, Aug 02, 2012 at 10:33:19AM -0400, Calvin Morrison wrote:

I think cut is exactly the kind of job that awk (or sed) can be good
for. It seems crazy not to use an existing tool that implements all
the functionality, that can be nicely bundled in a a script.


To be honest, I feel the same way about head(1) -- why bother
maintaining C when the tool is obviously a subset of another tool?

This is what happens.

http://perllinux.sourceforge.net/
"A Linux distribution where ALL programs are written in perl."

Uriel | 3 Aug 2012 20:02

Re: [PATCH] sbase: add cut

On Thu, Aug 2, 2012 at 4:34 PM, Kurt H Maier <khm-suckless <at> intma.in> wrote:
> On Thu, Aug 02, 2012 at 10:33:19AM -0400, Calvin Morrison wrote:
>>
>> I think cut is exactly the kind of job that awk (or sed) can be good
>> for. It seems crazy not to use an existing tool that implements all
>> the functionality, that can be nicely bundled in a a script.
>>
>
> To be honest, I feel the same way about head(1) -- why bother
> maintaining C when the tool is obviously a subset of another tool?

head(1) is utterly and completely idiotic. sed 11q is superior in
every possible way.

Calvin Morrison | 3 Aug 2012 20:08
Picon
Gravatar

Re: [PATCH] sbase: add cut

On 3 August 2012 14:02, Uriel <uriel <at> berlinblue.org> wrote:
> On Thu, Aug 2, 2012 at 4:34 PM, Kurt H Maier <khm-suckless <at> intma.in> wrote:
>> On Thu, Aug 02, 2012 at 10:33:19AM -0400, Calvin Morrison wrote:
>>>
>>> I think cut is exactly the kind of job that awk (or sed) can be good
>>> for. It seems crazy not to use an existing tool that implements all
>>> the functionality, that can be nicely bundled in a a script.
>>>
>>
>> To be honest, I feel the same way about head(1) -- why bother
>> maintaining C when the tool is obviously a subset of another tool?
>
> head(1) is utterly and completely idiotic. sed 11q is superior in
> every possible way.
>

Might as well have a shell alias or even a script to do it for you.
Either way the point I think is that these formatting programs are
better suited to a program designed to handle all sorts of character
stream manipulation.

Connor Lane Smith | 3 Aug 2012 20:57
Favicon
Gravatar

Re: [PATCH] sbase: add cut

On 3 August 2012 19:02, Uriel <uriel <at> berlinblue.org> wrote:
> head(1) is utterly and completely idiotic. sed 11q is superior in
> every possible way.

% head -n -10

% sed -e :a -e '$d;N;2,10ba' -e 'P;D'

No thanks.

cls

Kurt H Maier | 3 Aug 2012 22:10
Picon
Favicon

Re: [PATCH] sbase: add cut

On Fri, Aug 03, 2012 at 07:57:38PM +0100, Connor Lane Smith wrote:
> On 3 August 2012 19:02, Uriel <uriel <at> berlinblue.org> wrote:
> > head(1) is utterly and completely idiotic. sed 11q is superior in
> > every possible way.
> 
> % head -n -10
> 
> % sed -e :a -e '$d;N;2,10ba' -e 'P;D'
> 
> No thanks.
> 
> cls
> 

$ head -n -10
head: illegal line count -- -10

Nick | 3 Aug 2012 23:15
Picon
Favicon

Re: [PATCH] sbase: add cut

Quoth Connor Lane Smith:
> % head -n -10

Cool, I didn't know that syntax. Useful. Out of curiousity, is it 
codified in any standard?

Connor Lane Smith | 3 Aug 2012 23:55
Favicon
Gravatar

Re: [PATCH] sbase: add cut

On 3 August 2012 22:15, Nick <suckless-dev <at> njw.me.uk> wrote:
> Cool, I didn't know that syntax. Useful. Out of curiousity, is it
> codified in any standard?

Sadly not. But then, most things aren't.

cls

Uriel | 4 Aug 2012 02:37

Re: [PATCH] sbase: add cut

On Fri, Aug 3, 2012 at 11:15 PM, Nick <suckless-dev <at> njw.me.uk> wrote:
> Quoth Connor Lane Smith:
>> % head -n -10

Yea, because obviously what we needed is even more unportable GNU extensions.

If this is your only justification for head, it is really sad.

> Cool, I didn't know that syntax. Useful. Out of curiousity, is it
> codified in any standard?
>

Connor Lane Smith | 4 Aug 2012 02:51
Favicon
Gravatar

Re: [PATCH] sbase: add cut

On 4 August 2012 01:37, Uriel <uriel <at> berlinblue.org> wrote:
> Yea, because obviously what we needed is even more unportable GNU extensions.

I don't know about you, but I'd rather use an effective unportable
tool than an ineffective portable one.

cls

Kurt H Maier | 4 Aug 2012 04:40
Picon
Favicon

Re: [PATCH] sbase: add cut

On Sat, Aug 04, 2012 at 01:51:27AM +0100, Connor Lane Smith wrote:
> 
> I don't know about you, but I'd rather use an effective unportable
> tool than an ineffective portable one.
> 

I'd rather use an effective portable one, and pretending that doesn't
exist doesn't help anything.  

Strake | 4 Aug 2012 02:01
Picon

Re: [PATCH] sbase: add cut

On 03/08/2012, Connor Lane Smith <cls <at> lubutu.com> wrote:
> % head -n -10

Not sbase head.

$ seq 0 7 | head -n -2
$

Connor Lane Smith | 4 Aug 2012 02:07
Favicon
Gravatar

Re: [PATCH] sbase: add cut

On 4 August 2012 01:01, Strake <strake888 <at> gmail.com> wrote:
> Not sbase head.

Maybe someone should file a bug. :p

By the way, POSIX tail accepts both positive and negative '-n'
arguments, so it would make sense if head did too. One might expect
'-c' as well. Unfortunately standards seldom make much sense.

cls

Andrew Hills | 2 Aug 2012 02:33
Picon

Re: [PATCH] sbase: add cut

On Wed, Aug 1, 2012 at 6:54 PM, Kurt H Maier <khm-suckless <at> intma.in> wrote:
> The question is: since cut can be implemented IN awk, why should it get
> a separate C binary?  Anyone nattering about performance in a shell
> script is barking up the wrong tree.

Should sed be excluded? What can you do with sed that you can't do in
awk? For that matter, since Perl can do just about everything, if not
as quickly or easily, why not support just Perl, and no other tools?

--Andrew Hills

Kurt H Maier | 2 Aug 2012 03:58
Picon
Favicon

Re: [PATCH] sbase: add cut

On Wed, Aug 01, 2012 at 08:33:14PM -0400, Andrew Hills wrote:
> On Wed, Aug 1, 2012 at 6:54 PM, Kurt H Maier <khm-suckless <at> intma.in> wrote:
> > The question is: since cut can be implemented IN awk, why should it get
> > a separate C binary?  Anyone nattering about performance in a shell
> > script is barking up the wrong tree.
> 
> Should sed be excluded? What can you do with sed that you can't do in
> awk? For that matter, since Perl can do just about everything, if not
> as quickly or easily, why not support just Perl, and no other tools?
> 
> --Andrew Hills
> 

relax, genius.  I'm not proposing that we drop cut.  I'm asking why it
has to be written in C instead of a higher-level language.

sed is not trivial to write in awk.  there is nothing you can't do,
obviously, because awk is turing-complete.  I realize that you're just
being a shit, but sed is a text editor, and cut is a thing written for
people who couldn't be bothered to learn things.  In fact, I'm fairly
certain I could implement cut in sed.

I'm going to ignore your "take the concept to the extreme" straw man
because it isn't interesting.  I'm asking for clear cases where binary cut
is obviously superior, and not a bunch of whining because you're used to 
it being an individual binary.  If you can't deliver, maybe Steven
Blatchford can?

Strake | 2 Aug 2012 04:21
Picon

Re: [PATCH] sbase: add cut

On 01/08/2012, Kurt H Maier <khm-suckless <at> intma.in> wrote:
> In fact, I'm fairly
> certain I could implement cut in sed.

with shell script wrapper?

Uriel | 1 Aug 2012 22:13

Re: [PATCH] sbase: add cut

On Wed, Aug 1, 2012 at 3:18 PM, Martin Kopta <martin <at> kopta.eu> wrote:
> On 08/01/2012 03:09 PM, Kurt H Maier wrote:
>>
>> On Wed, Aug 01, 2012 at 08:58:00AM -0400, Niki Yoshiuchi wrote:
>>>
>>> Why would you use awk or Perl when you have the best programming language
>>> available: Ruby?
>>> On Aug 1, 2012 8:55 AM, "Martin Kopta" <martin <at> kopta.eu> wrote:
>>>
>>>> On 08/01/2012 02:36 PM, Uriel wrote:
>>>>
>>>>> Use awk.
>>>>>
>>>>
>>>> Use Perl.
>>>>
>>>>
>>>>
>>
>> I hereby declare this mail thread a disaster area of top-posting and
>> language fanboyism and request immediate dispatch of the vans.
>>
>> Also, I'm really curious why people use cut when awk exists.
>
>
> $ du -b /usr/bin/cut /usr/bin/gawk /opt/plan9/bin/awk
> 38600   /usr/bin/cut
> 400212  /usr/bin/gawk
> 105700  /opt/plan9/bin/awk

You don't mention if they are statically or dynamically linked.

> Why would I use awk of which I don't remember syntax, when I could often do
> with trustworthy cut easily? Seriously, apart from '{print $1}' and doing
> sums and stuff, I don't know awk. I don't want to. It is weird intermezzo
> between simple cut/sed/.. and almighty perl. Never understood awk users.

Awk is so simple that there is simply no excuse for not knowing it
properly, if you use Unix you should know awk.

Also The Awk Programming Language is one of the best technical books
ever written, and everyone who uses Unix should have read it.

Uriel

Christoph Lohmann | 1 Aug 2012 15:10

Re: [PATCH] sbase: add cut

Greetings.

On Wed, 01 Aug 2012 15:10:19 +0200 Niki Yoshiuchi <aplusbi <at> gmail.com> wrote:
> Why would you use awk or Perl when you have the best programming language
> available: Ruby?
> On Aug 1, 2012 8:55 AM, "Martin Kopta" <martin <at> kopta.eu> wrote:
> 
> > On 08/01/2012 02:36 PM, Uriel wrote:
> >
> >> Use awk.
> >>
> >
> > Use Perl.

Conclusion #1: Awk and Perl people do not know how to construct a sentence.
Conclusion #2: Ruby people toppost.

I thought such cultures were eradicted five years ago.

And  now  stop promoting prototype languages, we are doing serious busi‐
ness here.

Sincerely,

Christoph Lohmann

Strake | 1 Aug 2012 16:42
Picon

Re: [PATCH] sbase: add cut

So, the new version, cut.c only, all else same:

diff -r 8cf300476909 cut.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cut.c	Wed Aug 01 09:41:11 2012 -0500
 <at>  <at>  -0,0 +1,188  <at>  <at> 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <utf.h>
+#include "text.h"
+#include "util.h"
+
+typedef struct {
+	int min, max;
+} range;
+
+int inRange (range r, unsigned int n) {
+	if ((0 == r.max || n <= r.max) && n >= r.min) return 1;
+	else return 0;
+}
+
+int fputrune (Rune r, FILE *f) {
+	char x[UTFmax];
+	int n;
+	n = runetochar (x, &r);
+	fwrite (x, 1, n, f);
+	return n;
+}
+
+void cutLineF (Rune d, unsigned int s, range *rs, char *x) {
+	int ii, n, nMax;
+	char **xs;
+	if (!utfrune (x, d)) {
+		if (!s) fputs (x, stdout);
+		return;
+	}
+	xs = malloc (sizeof (char *) * (strlen (x) + 2));
+	if (!xs) eprintf ("cut:");
+	for (n = 1; x; n++) {
+		xs[n] = x;
+		x = utfrune (x, d);
+		if (x) x += runelen (d);
+	}
+	nMax = n;
+	xs[nMax] = xs[0] + strlen (xs[0]);
+	for (ii = 0; rs[ii].min; ii++) {
+		if (nMax <= rs[ii].min) continue;
+		for (n = rs[ii].min; (rs[ii].max ? n <= rs[ii].max : 1) && n < nMax; n++) {
+			char ch = *xs[n+1];
+			*xs[n+1] = 0;
+			fputs (xs[n], stdout);
+			*xs[n+1] = ch;
+		}
+	}
+	free (xs);
+}
+
+void cutLineC (range *rs, char *x) {
+	Rune _r;
+	int ii, n;
+	for (ii = 0; rs[ii].min; ii++) {
+		char *y;
+		y = x;
+		for (n = 1; *y; n++) {
+			int l = chartorune (&_r, y);
+			if (inRange (rs[ii], n)) fwrite (y, 1, l, stdout);
+			y += l;
+		}
+	}
+}
+
+void cutLineB (range *rs, char *x) {
+	int ii, n;
+	for (ii = 0; rs[ii].min; ii++) {
+		for (n = rs[ii].min - 1; rs[ii].max ? n < rs[ii].max : x[n]; n++) {
+			fputc (x[n], stdout);
+		}
+	}
+}
+
+void go (int mode, Rune d, unsigned int s, range *rs, FILE *f) {
+	char *x;
+	size_t size = 0;
+	x = 0;
+
+	while (afgets (&x, &size, f)) {
+		int ii;
+		/* must delete newline here, and redo later;
+		   otherwise, unknown whether it was included in cut */
+		for (ii = 0; x[ii]; ii++) if (x[ii] == '\n') x[ii] = 0;
+		switch (mode) {
+		case 'f':
+			if (!utfrune (x, d)) {
+				if (s) break;
+				fputs (x, stdout);
+			}
+			else cutLineF (d, s, rs, x);
+			fputc ('\n', stdout);
+			break;
+		case 'c': cutLineC (rs, x); fputc ('\n', stdout); break;
+		case 'b': cutLineB (rs, x); fputc ('\n', stdout); break;
+		}
+	}
+}
+
+int main (int argc, char *argu[]) {
+	int mode = 0;
+	Rune d = '\t';
+	unsigned int s = 0;
+	range *rs = 0;
+	int ii;
+	
+	/* parse options */
+	for (ii = 1; ii < argc; ii++) {
+		int jj;
+		if (argu[ii][0] != '-' || argu[ii][1] == 0) break;
+		if (argu[ii][1] == '-' && argu[ii][2] == 0) {
+			ii++;
+			break;
+		}
+		for (jj = 1; argu[ii][jj]; jj++) switch (argu[ii][jj]) {
+		case 'b':
+		case 'c':
+		case 'f':
+			mode = argu[ii][jj];
+			
+			if (++ii >= argc) {
+				fputs ("cut: No range argument\n", stderr);
+				return 1;
+			}
+			
+			rs = malloc (sizeof (range) * (utflen (argu[ii]) + 1));
+			if (!rs) eprintf ("cut:");
+			
+			/* ensure space delimitation for strtoul */
+			for (jj = 0; argu[ii][jj]; jj++) if (argu[ii][jj] == ',')
argu[ii][jj] = ' ';
+			
+			/* parse ranges */
+			/* max = 0 to denote last */
+			{
+				char *p;
+				p = argu[ii];
+				jj = 0;
+				while (*p) {
+					rs[jj].min = *p == '-' ? 1 : strtoul (p, &p, 10);
+					rs[jj].max = *p == '-' ? strtoul (++p, &p, 10) : rs[jj].min;
+					switch (*p) {
+					case '\0':
+						rs[++jj].min = 0;
+						break;
+					case ' ':
+					case '\f':
+					case '\v':
+					case '\t':
+					case '\r':
+					case '\n':
+						jj++;
+						break;
+					default:
+						fputs ("cut: Malformed ranges\n", stderr);
+						return 1;
+					}
+				}
+			}
+			goto nextArgument;
+		case 'd':
+			chartorune (&d, argu[++ii]);
+			goto nextArgument;
+		case 's':
+			s = 1;
+			break;
+		}
+nextArgument:	;
+	}
+
+	if (!mode) {
+		fputs ("cut: No mode given\n", stderr);
+		return 1;
+	}
+	
+	if (ii < argc) {
+		for (; ii < argc; ii++) {
+			FILE *f;
+			f = strcmp ("-", argu[ii]) == 0 ? stdin : fopen (argu[ii], "r");
+			if (!f) eprintf ("cut: %s:", argu[ii]);
+			go (mode, d, s, rs, f);
+			if (f != stdin) fclose (f);
+		}
+	}
+	else go (mode, d, s, rs, stdin);
+	
+	return 0;
+}


Gmane