- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- perl script
Operating System - Linux
1756020
Members
2587
Online
108839
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2006 09:09 PM
07-09-2006 09:09 PM
perl script
Hi...
I wanted split a file and move certain no of lines from that file to another.
i.e I need to take out first 800 lines in a file and move to a new file and then the next 800 to another new file,etc...
I wrote the below coding,but I could not take out the line from the old file...plz help me out in finding the mistake in my code
#!/usr/bin/perl
use strict;
use warnings;
my $logfiles_dir_path = '/home/rsaravanan/rekha/assignments/log';
opendir DH, $logfiles_dir_path or die "Cannot open dir $logfiles_dir_path : $!";
foreach my $logfilename (readdir DH)
{
my $logfile = $logfiles_dir_path .'/'.$logfilename;
open(FH, $logfile) or die "Can't open $logfile: $!";;
my @file_lines =;
close(FH);
my $line_count = 0;
while (@file_lines)
{
my $i = 1;
#my $line_count = 0;
my $new_filepath = $logfiles_dir_path .'/'.$logfilename.'.'.'file'.$i;
open DATAOUT, ">>$new_filepath" or die "can't open $new_filepath $!";
#until($line_count == 5)
#{
foreach my $line (@file_lines)
{
my $out = shift @file_lines;
#print $out;
print DATAOUT "$out";
}
# $line_count++;
# }
close(DATAOUT);
$i++;
}
}
close(DH);
I wanted split a file and move certain no of lines from that file to another.
i.e I need to take out first 800 lines in a file and move to a new file and then the next 800 to another new file,etc...
I wrote the below coding,but I could not take out the line from the old file...plz help me out in finding the mistake in my code
#!/usr/bin/perl
use strict;
use warnings;
my $logfiles_dir_path = '/home/rsaravanan/rekha/assignments/log';
opendir DH, $logfiles_dir_path or die "Cannot open dir $logfiles_dir_path : $!";
foreach my $logfilename (readdir DH)
{
my $logfile = $logfiles_dir_path .'/'.$logfilename;
open(FH, $logfile) or die "Can't open $logfile: $!";;
my @file_lines =
close(FH);
my $line_count = 0;
while (@file_lines)
{
my $i = 1;
#my $line_count = 0;
my $new_filepath = $logfiles_dir_path .'/'.$logfilename.'.'.'file'.$i;
open DATAOUT, ">>$new_filepath" or die "can't open $new_filepath $!";
#until($line_count == 5)
#{
foreach my $line (@file_lines)
{
my $out = shift @file_lines;
#print $out;
print DATAOUT "$out";
}
# $line_count++;
# }
close(DATAOUT);
$i++;
}
}
close(DH);
- Tags:
- Perl
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2006 09:16 PM
07-09-2006 09:16 PM
Re: perl script
However much I love perl, why not use split or csplit here?
The right tool for the right problem.
Enjoy, Have FUN! H.Merijn
The right tool for the right problem.
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
- Tags:
- split
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP