Sponsored Content
Full Discussion: wc -l
Top Forums Shell Programming and Scripting wc -l Post 302168880 by olenkline on Tuesday 19th of February 2008 04:38:50 PM
Old 02-19-2008
Split file wc -l

Here's a stab at it.

==========Script follows ===========
#!/bin/ksh
filename=$1
tline=$(wc -l $filename | awk '{print $1}')
let hline=$tline/2
split -l $hline $filename
=========== End of script ==========

This will output 2 files, call xaa and xab by default, check the man page for split to see how to make it what you want.

Syntax to execute it is scriptname [file_to_be_split]

Variable definitions
filename - file to be split
tline - number of lines in the file
hline - 1/2 of the number of lines in the file

Hope this helps, sure there are other ways.

Last edited by olenkline; 02-19-2008 at 05:52 PM.. Reason: Use of obsolete ` in Ksh script, and forgot a '
 
All times are GMT -4. The time now is 08:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy