The most minimalist answer to this problem is to use my cuts
utility:
$ cat file.txt
text,blah,blaah,foo
this,is,another,text,line
$ cuts -2 file.txt
blaah
text
cuts, which stands for "cut on steroids":
- automatically figures out the input field separators
- supports multi-char (and regexp) separators
- automatically pastes (side-by-side) multiple columns from multiple files
- supports negative offsets (from end of line)
- has good defaults to save typing + allows the user to override them
and much more.
I wrote cuts
after being frustrated with the too many limitations of cut
on Unix. It is designed to replace various cut
/paste
combos, slicing and dicing columns from multiple files, with multiple separator variations, while imposing minimal typing from the user.
You can get cuts
(free software, Artistic Licence) from github: https://github.com/arielf/cuts/
Calling cuts
without arguments will print a detailed Usage
message.