| > Ruby and Perl have awk modes Yes, but not Python. azalemeth was wondering if Python could be more terse than sed for this type of work. I think Python tends to be the most verbose among all languages discussed for text handling. > There's basically no advantage that awk has over Ruby There are a few. The main advantage of awk over ruby for me is that it's more terse for some simple jobs. That's because of features like - how unused variables can be used as numbers, strings, or associative arrays without previous declaration. For example, in the common snippet `awk '!a[$0]++'`, `a` is referenced as an array without having to declare it as such first, and the returned value is used as a number (i.e. by `++`) without having to declare that as such. - how number strings can be implicitly used as numbers - how records are split by default in a very useful way, with each field made available in a very terse manner with the `$` unary operator. - how plain regexes can be used as booleans that match over the line. - how simply passing a boolean expression means to print records that match. It also helps that records can be multi-line or be defined by regexes. - how ranges can be specified with a couple of boolean expressions - how files and co-processes can be implicitly opened on first use It also has advantage in that - It launches much quicker in comparison to most languages. I recently did a small shell DSL using many piped calls to awk to write some extensions for i3, and performance was decent, surprisingly. jq calls were a far bigger bottleneck. - It's available on even really old systems. It can be refreshing at times when your only other options are sh, C, or 4GL. There are many cases where awk is more convenient than ruby. |