Obviously, other people have different experiences which is why I quality it so. (I only narrowly missed it at the beginning, but I started in webdev, and we never quite took direct feeds from the mainframes.) But I don't think it's too crazy to say UNIX shell, to the extent it can be pinned down at all, works most natively with variable-length line-by-line content.
SAP comes to mind. I think it does support various different formats, but for reason or another fixed-width seemed to be some kind of default value (that's what I usually got when I asked for SAP feed at least, but that was years ago).
Admittedly I have encountered fixed-width text formats in the wild. But the last such occasion was about 15 years ago. (It was for interacting with a credit card processor to issue reward cards.)
and my favourite....... - source code.
My first intro to awk was using it to process COBOL code to find redundant copy libs, consolidate code, and generally cleanup code (very very crude linting). And it was brilliant. Fast, logical, readable, reliable - was everything i needed.
It is also an eminently suitable language for teaching programming because it introduces the basic concept of SETUP - LOOP - END . which is exactly the same as one will find in most business systems, you find it in arduino sketches, hell you even find it in a browser which is basically just a whole universe of stuff sitting atop a very fast loop that looks for events.
AWK fan for sure - my heirachy of languages these days would be cmd line where there is specific command doing all i need, AWK for anything needing to slice and dice records that dont contain blobs, python for complete programs, and python+nuitka or lazarus or C# when need speed and/or cross platform.
Select characters 3-6 (inclusive) in the second field:
$ echo Testing LengthyString | awk '{print substr($2,3,4)}'
> ngth
If you want to select columns from the entire line, then:
$ echo Testing LengthyString | awk '{print substr($0,3,4)}'
> stin
Is that what you meant?
Or you can use loops, e.g.,
echo $(seq 100) | awk '{ for (i = 2; i <= 7; i++) { print $i; }; }' cut -d, -f10-30
(selects from field 10 to 30)Not saying this can't be written in awk with more code, but we were talking about field selection ergonomics.
It doesn't detract from the point at hand - which is perfectly valid - but it's worth noting that there's a confusion here with regards the terminology: "fields" vs "columns". I thought they were referring to "columns of characters" whereas the added explanations[0] are about "columns of fields". That makes a difference.
But as I say, yes, I agree that to select a range of columns of fields, especially several fields from each line, is definitely better with cut.
Repo has a few other shortcuts, too: