Skip to content

Instantly share code, notes, and snippets.

@richsoni
Created August 9, 2013 13:03
Show Gist options
  • Save richsoni/6193465 to your computer and use it in GitHub Desktop.
Save richsoni/6193465 to your computer and use it in GitHub Desktop.
Cut Out Pieces Of A CSV in BASH
USAGE="Usage: csv_split file.csv (lines to be included use n..n as a range)"
if [ "$#" == 0 ]; then
echo "$USAGE"
exit 1
fi
filename=$1
shift
while (( "$#" )); do
OIFS=$IFS
IFS=".."
read -ra group <<< "$1"
IFS=$OIFS
START=${group[0]}
if [ ${group[2]} ]; then
END=${group[2]}
DIFF=$(($END-$START+1))
echo "`head -${END} $filename | tail -${DIFF}`"
else
echo "`head -${START} $filename| tail -1`"
fi
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment