Created
August 9, 2013 13:03
-
-
Save richsoni/6193465 to your computer and use it in GitHub Desktop.
Cut Out Pieces Of A CSV in BASH
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
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