I am using cygwin on windows.
I write this script. I have to split all files in the
directory.
Dir.foreach('C:/tmp/test') {|file|
f = system( "split -l 60000 #{file}")
puts "file name : #{f}"
}
My files is
file1.txt 10mb
file2.txt 14mb
file3.txt 8mb
file4.txt 5mb
I want to split the files
file1-1.txt
file1-2.txt
file1-3.txt
....
file4-1.txt
file4-2.txt
how can i do it ?
please help me.
···
--
Posted via http://www.ruby-forum.com/.
What (incorrect) output does your current script produce?
···
On Wed, Oct 7, 2009 at 6:19 AM, Ahmet Kilic <ahmedkilic@gmail.com> wrote:
I am using cygwin on windows.
I write this script. I have to split all files in the
directory.
Dir.foreach('C:/tmp/test') {|file|
f = system( "split -l 60000 #{file}")
puts "file name : #{f}"
}
I want to split the files
file1-1.txt
file1-2.txt
file1-3.txt
....
how can i do it ?
please help me.
unknown wrote:
file1-1.txt
file1-2.txt
file1-3.txt
....
how can i do it ?
please help me.
What (incorrect) output does your current script produce?
the output is only
xaa
xab
xac
xad
...
I want to loop all files and split for each around 1mb.
···
On Wed, Oct 7, 2009 at 6:19 AM, Ahmet Kilic <ahmedkilic@gmail.com> > wrote:
--
Posted via http://www.ruby-forum.com/\.
Okay, that helps; looks like by default split names the files "xaa".."xzz":
http://unixhelp.ed.ac.uk/CGI/man-cgi?split
As as first pass (still won't be quite what you asked for) try changing:
"split -l 60000 #{file}"
to:
"split -l 60000 #{file} #{file}-"
that should change the output file names from "x" + "#{counter}" to
"#{file}" + "-" + "#{counter}"
···
On Wed, Oct 7, 2009 at 11:25 AM, Ahmet Kilic <ahmedkilic@gmail.com> wrote:
unknown wrote:
On Wed, Oct 7, 2009 at 6:19 AM, Ahmet Kilic <ahmedkilic@gmail.com> >> wrote:
file1-1.txt
file1-2.txt
file1-3.txt
....
how can i do it ?
please help me.
What (incorrect) output does your current script produce?
the output is only
xaa
xab
xac
xad
...
I want to loop all files and split for each around 1mb.
Sorry, yes that was unclear; it was just representing the "aa".."az"
that split tacks on to the end of the file name. So, I'm thinking
that will produce output files named like:
file1.txt-aa
file1.txt-ab
file1.txt-ac
file2.txt-aa
file3.txt-ab
...
···
On Wed, Oct 7, 2009 at 11:57 AM, Ahmet Kilic <ahmedkilic@gmail.com> wrote:
As as first pass (still won't be quite what you asked for) try changing:
"split -l 60000 #{file}"
to:
"split -l 60000 #{file} #{file}-"
that should change the output file names from "x" + "#{counter}" to
"#{file}" + "-" + "#{counter}"
thank you for quick reply. I cold not understand counter. Where is it
coming?
like this counter = 0
and counter file + 1 ???
Ahmet Kilic wrote:
unknown wrote:
thank you for quick reply. I cold not understand �counter. Where is it
coming?
like this counter = 0
and �counter file + 1 ???
Sorry, yes that was unclear; it was just representing the "aa".."az"
that split tacks on to the end of the file name. So, I'm thinking
that will produce output files named like:
file1.txt-aa
file1.txt-ab
file1.txt-ac
file2.txt-aa
file3.txt-ab
...
sorry for late reply.
I was thinking like that but it was not work for me.
thank you for help.
use
split -d -l 60000 ${file} ${file}-
which should give you files of the format
$file-01
$file-02
$file-0...
if the split file is going to generate more than 99 files, add -a 4 to the parameters...
i.e.
split -d -l 60000 MyFile.txt MyFile.txt-
gives
MyFile.txt-01
MyFile.txt-02
MyFile.txt-03
MyFile.txt-...
Then write a script that renames the files ala
for file in `ls MyFile.txt-*`
do
prefix=${file%%.txt*}
# echo $prefix
suffix=${file##file.txt}
# echo $suffix
echo ${prefix}${suffix}.txt
mv $file ${prefix}${suffix}.txt
done
···
On Wed, Oct 7, 2009 at 11:57 AM, Ahmet Kilic <ahmedkilic@gmail.com> >> wrote: