Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

todays challenge: automate csplit of large file

Status
Not open for further replies.

WiccaChic

Technical User
Jan 21, 2004
179
US
I am totally trying to leach of your brain matter. We run AIX and sometime we get huge text files that we need to split into say four equal (or near equal) parts. We use the csplit command to do this. For instance I just di the following for file BIGFILE:

$: wc BIGFILE
3322657 176809963 3623691354 BIGFILE

So I divided 3322657 by four, did some rounding and addition to get my csplit starting points and then did:
$: csplit pdc_txt_P0055.txt 830664 1661328 2491992

Which got me four fractions of the original data. Can someone show me how to script this out so my ops could just enter a file name and enter the number of parts to split it into?
 
Something like this ?
read f?"File name "
read n?"Number of parts "
typeset -i l=$(wc -l < $f)
csplit -k $f $(((l+n-1)/n)) {$n}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV!!! U'da man! Or woman as far as I know. Thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top