Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active January 2, 2016 20:29
Show Gist options
  • Select an option

  • Save coderofsalvation/8357289 to your computer and use it in GitHub Desktop.

Select an option

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!
# 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