Created
August 17, 2012 18:28
-
-
Save ivan-krukov/3381362 to your computer and use it in GitHub Desktop.
This atrocious shell script prints the first 1/nth (half, third, etc) part of a file
This file contains 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
#!/bin/sh | |
#get the command line arguments | |
input_file=$1 | |
divisor=$2 | |
#run wc on the file in argv[1] | |
size=`wc -l $input_file` | |
#split the return on whitespace - first word is now in | |
set $size | |
#get the intiger division of wc/divisor | |
part=$(($1/$divisor)) | |
#print the first part (wc/divisor) | |
head -$part $input_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example run:
sh split.sh file n
N is the divisor