Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@ivan-krukov ivan-krukov commented Aug 17, 2012

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
You can’t perform that action at this time.