3 ms·
It is funny that sed and awk are often uttered together as one incantation, while in fact they are very different tools. Sed is, I dare to say, one of these q
by kunley 3y ago
It is funny that sed and awk are often uttered together as one incantation, while in fact they are very different tools.
Sed is, I dare to say, one of these quick-hack tools Unix is full of; awk in turn os a great mini-language with the defaults and builtins allowing for very concise programs.
What they share in common is processing lines and using regexes, and here's where similarities end.
While there is this sentiment to attribute a notion of "oldness" to awk, it is very powerful tool and is being implemented every decade (hello, GoAwk!). The rhetorical question, if it's so ancient and legacy, whether it's being reinvented every now and then?
This is a little detour from the original point, that was: processing structured data. Going back to this, I think there is important distinction: are we ok with the tools processing raw input/output and interpreting structure internally, or are we in a desperate need to preserve the structure in the piping mechanism, like Marcel does?
The latter ofc gives more power; but the former retains the compatibility with all the tools that don't know the structure.
- geophile 3y agoThis is a false choice. You can start with minimal structure, add it for intermediate processing and then go back to text, if you’d like. Marcel can run native commands, piping their output into other Marcel commands, as a steam of strings.
- kunley 3y agoYeah, ok that's a valid view. I will give Marcel a try for sure, thanks.
- geophile 3y agoCool. To address one of your other comments: "but the former retains the compatibility with all the tools that don't know the structure." Marcel plays nicely with host executables. The strings generated by an executable can be streamed into marcel commands. Marcel structured output can be piped into executables as strings. Example 1: Compute distribution of word lengths. This pipes cat output into marcel commands: cat /usr/share/dict/words | (w: (len(w), 1)) | red . + | sort (Or you could replace cat by the marcel command "read".) Example 2: Generate tuples of the form (i, i) and then have sed work on them. gen 10 | (x: (x, x)) | sed s/5/xxx/g The (5, 5) tuple is replaced by (xxx, xxx)