Last active
January 2, 2016 20:29
-
-
Save coderofsalvation/8357289 to your computer and use it in GitHub Desktop.
the 'chucknorris' cut, easily extracts fields/columns from console output. When 'cut' fails: use supercut!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # the 'chucknorris'-cut, handy for csv and ls, removes double delimiters and such. When 'cut' fails: use supercut! | |
| # for csv parsing with quote-support use bashlive's 'csvget' | |
| # @param string columnnumber | |
| # @param string delimiter [optional, default: space] | |
| # usage: ls -la | supercut 4 <-- prints the 4th column | |
| # cat my.csv | supercut 3 ; <-- prints the 4rd column from a ';'-seperated csv without quotes | |
| supercut(){ | |
| [[ ! -n $2 ]] && delimiter=' ' || delimiter=${2:0:1}; cat - | tr -s "$delimiter" | cut -d"$delimiter" -f $1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment