LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2007, 09:00 AM   #16
Sherlock
Member
 
Registered: Mar 2004
Location: India
Distribution: RedHat Linux 8
Posts: 60

Original Poster
Rep: Reputation: 15

All i know is that its a Unix OS...no idea...whats the version and flavour
 
Old 02-02-2007, 12:22 AM   #17
Sherlock
Member
 
Registered: Mar 2004
Location: India
Distribution: RedHat Linux 8
Posts: 60

Original Poster
Rep: Reputation: 15
Hi,

Any other way???
 
Old 02-02-2007, 01:11 AM   #18
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
what does the cmd

uname -a

give you at the cmd line?
 
Old 02-02-2007, 02:32 AM   #19
Sherlock
Member
 
Registered: Mar 2004
Location: India
Distribution: RedHat Linux 8
Posts: 60

Original Poster
Rep: Reputation: 15
I got the msg
Sun OS.......
 
Old 02-02-2007, 03:10 AM   #20
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
It's fine, we can do it on SunOS. It's a pity there's no switch to print out the names of the created files like there is on Linux systems. Maybe you should convert all you systems to Linux!

I would suggest this approach:
  1. choose a prefix for the output file names which you know will be unique
  2. do the split
  3. use readdir to get a list of the newly created files

Before we can start, can you check that the Sun implementation of split works as I hope?

First, make a test file containing the following text:
Code:
test line 1
test line 2
test line 3
test line 4
test line 5
test line 6
Now run split like this:
Code:
split -l 3 testfile myprefix_
Can you post the output of this command:
Code:
ls -l myprefix_*
If all is well, we can easily get the list of files by reading the directory listing, and filtering for some prefix we have chosen.

Last edited by matthewg42; 02-02-2007 at 03:11 AM.
 
Old 02-02-2007, 04:22 AM   #21
Sherlock
Member
 
Registered: Mar 2004
Location: India
Distribution: RedHat Linux 8
Posts: 60

Original Poster
Rep: Reputation: 15
I ran it...and thsi was the output

-rw-r----- 1 abcd xyz 36 Feb 2 13:21 myprefix_aa
-rw-r----- 1 abcd xyz 36 Feb 2 13:21 myprefix_ab
 
Old 02-02-2007, 04:52 AM   #22
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
OK, looks like sun's implementation of split does what I expected. Try this program (comments explain what it's doing):
Code:
#!/usr/bin/perl -w

use strict;

my $input_file = "mytestfile";   # or whatever your file is called...
my $lines_per_split_file = 3;    # or whatever you like

# choose a file prefix with a random element to reduce the risk
# of getting confused by old split files, and do a quick check to
# be sure there are no files with the same prefix already existing
my $prefix = sprintf("splitter%05d_",int(rand()*10000));
my @files = glob("$prefix*");
($#files < 0) || die "there are pre-existing files with prefix $prefix, ABORTING\n";

# OK, if we didn't die yet then it's OK to proceed with the splitting
system("split -l $lines_per_split_file \"$input_file\" $prefix");
$? && die "error running split\n";

# Now the split has been done, we can use glob to get a list of the
# files it has created.  note @files was already declared, so we don't
# need to declare it again.
@files = glob("$prefix*");

# Now the array @files contains the list of split files, you can go on
# to do whatever you like with it
foreach my $file (@files) {
        print "got a file name: $file\n";
}
 
Old 02-02-2007, 06:52 AM   #23
Sherlock
Member
 
Registered: Mar 2004
Location: India
Distribution: RedHat Linux 8
Posts: 60

Original Poster
Rep: Reputation: 15
Smile

Thanks matthewg42 !!! its working......
 
Old 02-02-2007, 12:24 PM   #24
Sherlock
Member
 
Registered: Mar 2004
Location: India
Distribution: RedHat Linux 8
Posts: 60

Original Poster
Rep: Reputation: 15
I found that even the input file would be part of the @files
at index 0
$files[0]

so i had to do shift(@files) before using only the split output files...

Last edited by Sherlock; 02-02-2007 at 12:26 PM.
 
Old 02-02-2007, 12:31 PM   #25
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
What is the prefix, and what is the original file in this case?
 
Old 02-02-2007, 12:43 PM   #26
Sherlock
Member
 
Registered: Mar 2004
Location: India
Distribution: RedHat Linux 8
Posts: 60

Original Poster
Rep: Reputation: 15
original File is say TestDump

and prefix is also TestDump

Of course if you have a prefix that has a different value...

itz a diff scenario...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split large file in several files using scripting (awk etc.) chipix Programming 14 10-29-2007 11:16 AM
Split Large Very Files (Software) kolmogorov Solaris / OpenSolaris 5 11-18-2005 11:46 AM
different names for output files rohr Programming 2 03-23-2005 09:44 AM
Split large file into multiples jdozarchuk Linux - Newbie 1 11-04-2004 09:42 AM
split a large mpeg file into two zstingx Linux - General 3 11-06-2003 06:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration