3 ms·
If you want to stick with Bash then the commands split, join, cut, paste, join come in very handy. For me there is a threshold beyond which I move to AWK. Some
by srean 3y ago
If you want to stick with Bash then the commands split, join, cut, paste, join come in very handy.
For me there is a threshold beyond which I move to AWK. Some would prefer Perl over AWK, but I cannot hold all of Perl's syntax and keywords in my brain.
Sometimes the needed processing is either a lot for AWK, or I have to be at my best behavior -- the equivalent of meeting my girlfriend's parents for the first time. In such cases I use Python. I usually do not use Python for one offs that I do not intend to maintain because with AWK you can usually relieve yourself of the ceremony of setting up a read and tokenize loop. Then again, some prefer making a sqlite database out of the file and use SQL.
TLDR: split, join, cut, paste, join, AWK.
Still TLDR: Coreutils (in particular textutils and fileutils) https://www.gnu.org/software/coreutils/manual/coreutils.html https://www.gnu.org/software/coreutils/manual/coreutils.html
This is not to insinuate that OP does not already know this, commenting just in the hope that it is helpful to some.
- ReleaseCandidat 3y ago> the commands split, join, cut, paste, join come in very handy. And uniq, you obviously forgot about uniq. Sorry, could not not respond to this ;)
- srean 3y agoIndeed ! Leaving my comment uncorrected for the unintended insider joke on why uniq would have helped.
- two_handfuls 3y agoAwk is great, but I don’t use it often enough to memorize the awk syntax. That’s why I use “pawk”, an awk-like tool with a Python syntax. It sets up the read and tokenize loop for me :)
- tzs 3y ago> For me there is a threshold beyond which I move to AWK. Some would prefer Perl over AWK, but I cannot hold all of Perl's syntax and keywords in my brain You don't have to hold all of a language's syntax and keywords in your brain to use that language. Or even be aware of all the syntax and keywords. It's fine to just learn the subset of a language needed for the things you are going to use it for.