ahmet
October 7, 2009, 12:18pm
1
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.
ahmet
October 7, 2009, 5:25pm
2
unknown wrote:
On Wed, Oct 7, 2009 at 6:19 AM, Ahmet K. [email protected]
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.
ahmet
October 7, 2009, 5:19pm
3
On Wed, Oct 7, 2009 at 6:19 AM, Ahmet K. [email protected]
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?
ahmet
October 7, 2009, 5:56pm
4
unknown wrote:
On Wed, Oct 7, 2009 at 11:25 AM, Ahmet K. [email protected]
wrote:
please help me.
I want to loop all files and split for each around 1mb.
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}”
thank you for quick reply. I cold not understand counter. Where is it
coming?
like this counter = 0
and counter file + 1 ???
ahmet
October 7, 2009, 5:40pm
5
On Wed, Oct 7, 2009 at 11:25 AM, Ahmet K. [email protected]
wrote:
please help me.
I want to loop all files and split for each around 1mb.
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}”
ahmet
October 8, 2009, 3:30am
6
unknown wrote:
On Wed, Oct 7, 2009 at 11:57 AM, Ahmet K. [email protected]
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.
ahmet
October 7, 2009, 6:10pm
7
On Wed, Oct 7, 2009 at 11:57 AM, Ahmet K. [email protected]
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
...
ahmet
October 8, 2009, 4:27am
9
Ahmet K. wrote:
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