I have this script to divide a file over a 100000 or even more in 50000 lines.
desc()
{
echo $1 $2|awk '{d=$1;}
BEGIN {a=1;b=0}
{ f=d"0"a;
while ((getline x<d)>0)
{ print x>>f".txt"
if (b++>=50000)
{
close(f);b=0;a++;f=(a<10)?d"0"a:f=d""a
}
}
}
END {print "Terminado ... ! "}'
}
if [ -f $1 ]; then
desc $1 $2
fi
When I execute it I got this error message:
sh-3.2$ parte.sh pa.txt
: command not found
'/parte.sh: line 2: syntax error near unexpected token `
'/parte.sh: line 2: `desc()
sh-3.2$
Can anyone help to solve it?
source script_name
? You probably need to add#!/bin/bash
if your script is executablesplit -l 50000 pa.txt pa
is much easier. If you want to keep the pa01.txt format, run this next:let c=1; for i in pa??; do mv $i $(printf "pa%02d.txt" $c); let c++; done