Skip to content

Instantly share code, notes, and snippets.

@ivan-krukov
Created August 17, 2012 18:28
Show Gist options
  • Save ivan-krukov/3381362 to your computer and use it in GitHub Desktop.
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
#!/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
@ivan-krukov
Copy link
Author

Example run:
sh split.sh file n
N is the divisor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment