3 ms·
When I need to do something like this I usually use sed. It's similar enough to vim that I don't have to remember too much. I've never liked perl at all and awk
by CalChris 9y ago
When I need to do something like this I usually use sed. It's similar enough to vim that I don't have to remember too much. I've never liked perl at all and awk doesn't offer that much more than sed. Maybe that'd be different if this sort of wrangling was a steady diet but it isn't. If I was gonna use awk I'd just skip straight on through to python.
- majewsky 9y ago> awk doesn't offer that much more than sed The one huge thing that sed is particularly bad at (unless I don't know the particular trick yet) is to split fields on a pattern. I frequently have pipes where sed is used for most of the text-processing, but then cut is used to select one (or multiple) character-separated fields, or awk is used to select one (or multiple) whitespace-separated fields. I only go one step further (usually to Perl) when operations involve multiple lines, e.g. when columns need to be summed up.
- kazinator 9y ago> awk doesn't offer that much more than sed Not much; just, oh, stuff like floating-point math and trig functions; integer math, associative arrays, access to environment variables, named functions with arguments and full recursion; control and looping structures like if, for and while, file I/O and redirection, string literals with C escapes, ... $ awk '$0=sin($1) + cos($2)' 0 1 0.540302 1 0 1.84147 How about sed? Just kidding ...
- CalChris 9y agoHoly double angle formula, Batman. Awk has command line trig functions? Riddle me this. Is the Google search bar just an Awk script and they won't tell you? That's just the sneaky kind of trick L+S would try.
- vram22 9y ago>awk doesn't offer that much more than sed Wrote this earlier in this same thread: https://news.ycombinator.com/item?id=14648534 https://news.ycombinator.com/item?id=14648534