On Thu, Apr 04, 2013 at 09:30:49AM +0200, Martti K??hne wrote:
> On Sun, Mar 31, 2013 at 4:53 AM, Calvin Morrison
> wrote:
> > Forget this whole LINE_MAX thing, I am looking at your suggestion in
> > the other message.
>
> For line buffering, I also use char arrays
I tend to use either a char a
On Sun, Mar 31, 2013 at 4:53 AM, Calvin Morrison wrote:
> Forget this whole LINE_MAX thing, I am looking at your suggestion in
> the other message.
>
> Thank you for the thorough review,
> Calvin
>
For line buffering, I also use char arrays, but I'd be looking for
line borders with strcspn(3) or
[2013-04-03 16:25] Sam Watkins
>
> using awk this seems to work:
>
> awk '{ gsub(A, B); print; }' A="$A" B="$B"
>
> Still a bit long, but much better than I can manage in sed or perl. Not sure
> if that is standard awk or not, there's also a -v option to set values.
Your version is the orig
> What is the shortest shell command you can write, that replaces $A with $B in
> a text stream for any A and B?
On Tue, Apr 02, 2013 at 06:32:19PM -0700, Noah Birnel wrote:
> A1="$(printf '%s' "$A" | sed 's,",\\",g; s,\\,,g')"
> B1="$(printf '%s' "$B" | sed 's,",\\",g; s,\\,,g')"
> awk '
On Tue, Apr 02, 2013 at 04:29:59PM +1100, Sam Watkins wrote:
>
> What is the shortest shell command you can write,
> that replaces $A with $B in a text stream for any A and B?
>
A1="$(printf '%s' "$A" | sed 's,",\\",g; s,\\,,g')"
B1="$(printf '%s' "$B" | sed 's,",\\",g; s,\\,,g')"
awk '{
>
> Please don't write this tool as it is already available: ed(1):
>
> echo '1,$-6p' | ed - "$1"
> echo '10,$--p' | ed - "$1"
better:
ed -s $1 <<"EOF"
1,$-6p
EOF
;)
Do note that gres(1) lives on as replace(1). Replace is maintained by
the MySQL team.
On Tue, Apr 02, 2013 at 01:29:11PM +0200, markus schnalke wrote:
> [2013-04-02 15:23] Sam Watkins
> >
> > I suggest to extend your program so it can also print a range of lines
> > (and thus subsume the functions of 'head' and 'tail' while doing more
> > and yet staying fairly focused). You coul
Sam Watkins was just testing him, now you spoiled it, lol.
On 4/2/13, markus schnalke wrote:
> [2013-04-02 15:23] Sam Watkins
>>
>> I suggest to extend your program so it can also print a range of lines
>> (and thus subsume the functions of 'head' and 'tail' while doing more
>> and yet staying f
[2013-04-02 15:23] Sam Watkins
>
> I suggest to extend your program so it can also print a range of lines
> (and thus subsume the functions of 'head' and 'tail' while doing more
> and yet staying fairly focused). You could perhaps use negative numbers
> to count back from the final line. It sho
[2013-04-02 15:36] Sam Watkins
> I reckon by far the most common thing people do with sed is to replace
> one (sort of) string with another. But even this "core sed business"
> is ridiculous with sed.
>
> e.g. A=/usr/bin B=/bin sed 's/$A/$B/' out # won't work
>
> Changing delimiters doesn't
On 2013-04-02 16:29, Sam Watkins wrote:
> > e.g. A=/usr/bin B=/bin sed 's/$A/$B/' out # won't work
>
> > I'm also not representative of the sed community, but to suggest that
> > this is what people primarily use it for is just ignorant.
>
> Ok perhaps I misjudged that, and I was a bit harsh on
> e.g. A=/usr/bin B=/bin sed 's/$A/$B/' out # won't work
> I'm also not representative of the sed community, but to suggest that
> this is what people primarily use it for is just ignorant.
Ok perhaps I misjudged that, and I was a bit harsh on sed. Sure, sed is
good at running ed scripts ove
On 2013-04-02 15:36, Sam Watkins wrote:
> I reckon by far the most common thing people do with sed is to replace
> one (sort of) string with another. But even this "core sed business"
> is ridiculous with sed.
>
> e.g. A=/usr/bin B=/bin sed 's/$A/$B/' out # won't work
>
> Changing delimiters d
I reckon by far the most common thing people do with sed is to replace
one (sort of) string with another. But even this "core sed business"
is ridiculous with sed.
e.g. A=/usr/bin B=/bin sed 's/$A/$B/' out # won't work
Changing delimiters doesn't help for the general case. I would have to
e
On Sat, Mar 30, 2013 at 10:27:05PM -0400, Calvin Morrison wrote:
> Is there a better way to read a whole line?
For this tool you don't need to read whole lines, just read blocks and
count newlines until you perhaps get to the right line number, and print
everything the next newline.
I agree that
On 03/31/2013 06:03 PM, Charlie Kester wrote:
Why add this extra complexity when stdio is already buffering the
input stream?
I did not mean to imply double-buffering. In fact, I figured I should've
linked to documentation on input streams seconds after I sent the mail.
On 03/31/2013 10:37, Bjartur Thorlacius wrote:
On 03/31/2013 01:52 PM, Charlie Kester wrote:
I'd read the file one character at a time, counting newlines, until I
reached the desired line. [..] Doing it this way avoids the need for a
buffer altogether, along with any guessing about possible line
On 03/31/2013 01:52 PM, Charlie Kester wrote:
I'd read the file one character at a time, counting newlines, until I
reached the desired line. [..] Doing it this way avoids the need for a
buffer altogether, along with any guessing about possible line lengths.
Reading is expensive. Loop through a
On 3/31/13, Calvin Morrison wrote:
> On Mar 31, 2013 9:57 AM, "Charlie Kester" wrote:
>>
>> On 03/30/2013 23:49, Chris Down wrote:
>>>
>>> GNU coreutils packages awful versions of
>>> awk/sed.
GNU awk and GNU sed are too big to be included in coreutils. They're
both separate packages.
> Sed d
On 03/31/2013 07:19, Calvin Morrison wrote:
Sed does many things and many things well, but the unix philosophy is to do
one thing and one thing well.
Perhaps you have too narrow an understanding of "one thing"?
As others have pointed out, the people who created Unix devised numerous
language
On 2013-03-31 10:19, Calvin Morrison wrote:
> Sed does many things and many things well, but the unix philosophy is to do
> one thing and one thing well.
What? I'm not even sure if this is serious any more...
These are interfaces to *languages*. The program does only one thing: interfaces
with th
Have you even read TUPE?
On Mar 31, 2013 4:19 PM, "Calvin Morrison" wrote:
>
> On Mar 31, 2013 9:57 AM, "Charlie Kester" wrote:
> >
> > On 03/30/2013 23:49, Chris Down wrote:
> >>
> >> I really don't see the need for a tool like this. Saying sed and awk are
> >> not suckless is like saying C is
On Mar 31, 2013 9:57 AM, "Charlie Kester" wrote:
>
> On 03/30/2013 23:49, Chris Down wrote:
>>
>> I really don't see the need for a tool like this. Saying sed and awk are
>> not suckless is like saying C is not suckless -- sed and awk are
languages
>> with a very specific domain, text processing.
On 03/30/2013 23:49, Chris Down wrote:
I really don't see the need for a tool like this. Saying sed and awk are
not suckless is like saying C is not suckless -- sed and awk are languages
with a very specific domain, text processing. Perhaps you think *an
implementation* sucks. Good. GNU coreutils
On 03/30/2013 19:27, Calvin Morrison wrote:
Is there a better way to read a whole line? fgets requires a length
argument, so I suppose it's not a very good solution
Framing the problem that way is where you went astray.
I'd read the file one character at a time, counting newlines, until I
re
I really don't see the need for a tool like this. Saying sed and awk are
not suckless is like saying C is not suckless -- sed and awk are languages
with a very specific domain, text processing. Perhaps you think *an
implementation* sucks. Good. GNU coreutils packages awful versions of
awk/sed. If y
On 3/30/13, Calvin Morrison wrote:
> On 30 March 2013 22:30, Robert Ransom wrote:
>> On 3/30/13, Calvin Morrison wrote:
>>> What do you guys think of the tool? Of the code? It does one thing and
>>> one thing well.
>>
>> Or perhaps you're just learning C and wanted someone to review your code.
>
On Sat, Mar 30, 2013 at 10:53 PM, Calvin Morrison
wrote:
> Should I have a seperate declaration and then intialization later or
> just combine the statements:
>
> int line = atoi(argv[2]);
>
> or
>
> int line;
> line = atoi(argv[2]);
>
that is a style question, most people like to read the functio
On 30 March 2013 22:30, Robert Ransom wrote:
> On 3/30/13, Calvin Morrison wrote:
>> What do you guys think of the tool? Of the code? It does one thing and
>> one thing well.
>
> Or perhaps you're just learning C and wanted someone to review your code.
A bit of both really, a good code review is
On 3/30/13, Calvin Morrison wrote:
>> - What guarantee do you have that the input file won't contain any lines
>> with length > LINE_MAX? As far as I know, that's an arbitrary number,
>> and
>> there is no intrinsic limit on the length of the lines in a Unix text
>> file.
>
> I didn't feel very g
On 3/30/13, Calvin Morrison wrote:
> What do you guys think of the tool? Of the code? It does one thing and
> one thing well.
Or perhaps you're just learning C and wanted someone to review your code.
Style issues:
* Error messages should be sent to stderr (s/printf(/fprintf(stderr, /
on error-m
On 30 March 2013 22:27, Charlie Kester wrote:
> On 03/30/2013 18:28, Calvin Morrison wrote:
>>
>> Comrades,
>>
>> I just spend about fifteen minutes writing this little tool that I call
>> print:
>>
>> http://mutantturkey.com/print/
>>
>> All it does is print the specified line from a file.
>>
>>
On 03/30/2013 18:28, Calvin Morrison wrote:
Comrades,
I just spend about fifteen minutes writing this little tool that I call print:
http://mutantturkey.com/print/
All it does is print the specified line from a file.
example usage:
$ print constitution.txt 1
We the People of the United State
On 3/30/13, Calvin Morrison wrote:
> Comrades,
>
> I just spend about fifteen minutes writing this little tool that I call
> print:
#!/bin/sh
sed -ne "$2"p "$1"
Comrades,
I just spend about fifteen minutes writing this little tool that I call print:
http://mutantturkey.com/print/
All it does is print the specified line from a file.
example usage:
$ print constitution.txt 1
We the People of the United States, in Order to form a more perfect Union,
$ p
36 matches
Mail list logo