18:14
@mikeserv will you please get over this obsession of yours that I have an agenda? What is it even supposed to be? I'm really fed up with waking up to comments whining about some kind of perceived agenda you think I have.
What, do you think I have anything against sed? I love sed! I think it's a great tool and wish I knew it as well as you do.
Of course sed isn't designed to work on fields! Come on! Of course it can be made to as it can be made to do just about anything, all I said there is that it is not designed for fields in the way that awk so obviously is.
To make sed understand fields, you need to build a regex that lets it do so. Awk and perl will automatically split on whitespace and give you direct access to the fields.
Anyway, none of this is remotely relevant. I have repeatedly asked you to post an answer showing the field capability of sed. Yet you refuse.
I'm sure that in the hands of an expert such as yourself it can work wonders, why do you insist on putting this in my answer instead of posting your own?
18:32
sed
is designed to work on whatever the fuck you want it to. It's a tool that does as its told. If you want it to work on fields - whatever that means - then thats what its designed to work on. You shouldn't post stuff like that - why spread ignorance like that? I can't get over it - it's appalling. 18:54
@mikeserv What is it you object to so much? I honestly don't know. I said "use a tool that is designed for fields, for example perl or awk or use regular expressions"
@mikeserv No it wasn't. In my original question, you kept coming back and posting another rant every 10 minutes or so. I'd stopped replying for ages.
The entire point of that post was to highlight that there are two basic approaches to dealing with field-based data: dedicated tools like awk or perl and more versatile things that use regexes for which I used sed as an example.
Just post it on your own answer. I don't understand why that's so hard for you to grok. Comments are not for extended discussions. 9 times out of 10, when we get an automatic flag about too many comments, it's because of you. "I don't like chat" is not good enough, that's no excuse to abuse the system dammit!
Anyway, I never said nor do I believe that sed is not capable of dealing with fields. Hell, I even chose to use it as an example of regex-based field dealings.
All I said is that sed, unlike awk, is not designed to work on fields. That is, very simply, a fact. As you very well know, sed is designed to work on streams, not fields. It has no knowledge or concept of fields. Of course it can be made to grok them but only because it is so versatile and can use regexes.
@mikeserv What? A way to do what? Deal with fields? And what does the source have to do with it? Of course it uses regexes in the background, the point is that the user doesn't need to.
In any case, whatever you do, you will never convince me that whatever brilliant esoteric sed thing you come up with to add 3 to the 5th field of every line will be simpler than `awk '{$5+=3}1;'. So yeah, sorry, but there are tools that are designed to work on on fields and tools that can be made to.
20:10
@mikeserv Write me a sed script that adds 3 to the value of the, say, 112th field of a line. Time it on a large file and show me that it's a) possible, b) easier than
awk '{$112+=3}1;
and c) faster than that awk. You're the one making claims here, not me, so you can bloody well prove them. If not, stop bugging me about this.
1 hour later…
21:36
Here's an example. I don't know if this is the most efficient way possible in sed but it's the best I got and seems to be the same as what you had added to my answer. First, let's create a file with 100,000 lines each of which has 200 fields (the numbers from 1 to 200):
$ time perl -lane '$F[111]="foo"; print "@F"' file > /dev/null real 0m11.115s user 0m11.052s sys 0m0.052s
OK, Perl is not too good here (though it still beats sed) precisely because we have to split the whole line but awk which is specifically designed for this type of thing is way faster than both perl and sed:
I guess you might find me a sed version that actually manages to beat the perl one but I very much doubt you'll be able to do that for the awk one. Because, surprisingly enough, awk is specifically designed to deal with field-based data.
I would also like to see how you get sed to add 3 to the value of the 112th field instead of replacing it. I have no idea if it's even possible and as far as I know it's not but hey,. the other two can do it because they know about fields:
22:26
And here, since you were so sure of yourself you wanted to add this one to my answer, compare perl, awk and sed when truncating at the 14th field (copied from your edit verbatim). I actually had to stop sed after the first 10 minutes since it was taking too long. The other 2 took seconds:
next day → last day (19 days later) »