Skip to content

Instantly share code, notes, and snippets.

@petrelharp
Created May 3, 2017 07:02
Show Gist options
  • Save petrelharp/81bd7ac59d6bcdbeae674d087f44c0c6 to your computer and use it in GitHub Desktop.
Save petrelharp/81bd7ac59d6bcdbeae674d087f44c0c6 to your computer and use it in GitHub Desktop.
View a file with lots of columns in chunks of N columns
#!/bin/bash
USAGE="Split a file up into chunks of N columns.
Usage:
$0 N file
"
if [ $# -lt 2 ]
then
echo "$USAGE"
exit 0
fi
N=$1
shift
FILE=$1
shift
NCOL=$(head -n 1 $FILE | wc -w)
START=1
while [ $START -le $NCOL ]
do
END=$((START+$N))
cut $* -f $START-$END $FILE | column -t
START=$((START+$N))
echo ""
echo "..........................................................."
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment