On Tuesday 04 October 2005 9:25 am, Brett Russ wrote:
On 10/4/05, Chuck Anderson <cra@wpi.edu> wrote:
On Tue, Oct 04, 2005 at 05:42:01PM +0700, Aramico wrote:
I have a log with more than 200000 lines in one single file. Can I split it into several defined files as file1, file2, file3, file4, filen where I can defined it for 20000 line for each ? How can I make it ? what command in linux to make it ?
The 'split' command can do that:
split -l 20000 -d --verbose file file
Ah, much easier :-)
OK, now that we know the easiest way, who can post the most obfuscated method? Not the MOST obfuscated, but darn near the slowest: If I could only embed that alst cur assignement!
#!/bin/sh if [ $# -lt 3 ] ; then echo "Usage: $0 <infile> <incr> <outfile_prefix>" exit fi while [ ${cur:=`wc -l $1| awk '{print $1}'`} -gt 0 ] ; do tail -$cur $1 | head -$2 > $3$(((`wc -l $1 | awk '{print $1}'` - $cur) / $2)) cur=$(( $cur - $2 )) done Thanks Brian