- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Spaces in file causing problems with my array
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
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
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- 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
тАО04-19-2005 10:16 PM
тАО04-19-2005 10:16 PM
#!/usr/bin/perl -w
`rm /tmp/tmp1/*`;
`cat /home1/reports/output/ljhbdss1/tmpftp >/tmp/tmp1/tmpfile`;
`cat /home1/reports/output/lptadss1/tmpftp >>/tmp/tmp1/tmpfile`;
`cat /home1/reports/output/lblmdss1/tmpftp >>/tmp/tmp1/tmpfile`;
`cat /home1/reports/output/lctndss1/tmpftp >>/tmp/tmp1/tmpfile`;
`cat /home1/reports/output/lpthdss1/tmpftp >>/tmp/tmp1/tmpfile`;
`cat /home1/reports/output/ldbndss1/tmpftp >>/tmp/tmp1/tmpfile`;
open (FOA, " > /tmp/tmp1/tmp.avg");
open (FOT, " > /tmp/tmp1/tmp.det");
open (FI, "< /tmp/tmp1/tmpfile") or die "Cannot find ljhbdss1 tmp file";
while ($line=
{
@LIST=(split/ /,($line));
chomp @LIST;
$var=$LIST[1];
print "creating $var\n";
sleep 1;
open (FN, ">> /tmp/tmp1/$var");
print FN @LIST,"\n";
close FN;
}
close FI;
close FOA;
close FOT;
exit
The input files has the following entries.
13.04.2005 r141DMZ1 10.203.63.6 100
14.04.2005 r141DMZ1 10.203.63.6 100
15.04.2005 r141DMZ1 10.203.63.6 100
16.04.2005 r141DMZ1 10.203.63.6 100
17.04.2005 r141DMZ1 10.203.63.6 100
18.04.2005 r141DMZ1 10.203.63.6 100
19.04.2005 r141DMZ1 10.203.63.6 100
20.04.2005 r141DMZ1 10.203.63.6 100
20.04.2005 r141DMZ1 10.203.63.6 100
r141DMZ1 Month_Availability 100.00
It bombs when reading the Month_Availability.
Can anyone show me how to eliminate the double spaces or ignore them preferably.
Regards
Solved! Go to Solution.
- Tags:
- evil spaces
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 10:28 PM
тАО04-19-2005 10:28 PM
Re: Spaces in file causing problems with my array
REPLACE the X's with same number of SPACES
live free or die
harry d brown jr
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 10:33 PM
тАО04-19-2005 10:33 PM
Re: Spaces in file causing problems with my array
IE
@LIST=(split/ /,($line));
tr / / /;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 10:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 11:00 PM
тАО04-19-2005 11:00 PM
Re: Spaces in file causing problems with my array
where are the double spaces in your input data file?
From what I see:
read the input file
append the record to a file named as the second field
This should create 1 file called r141DMZ1 with 9 records and 1 file called Month_Availability with 1 record.
Is this correct?
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 11:11 PM
тАО04-19-2005 11:11 PM
Re: Spaces in file causing problems with my array
But the field
r141DMZ1 Month_Availability 100.00
has spaces in between and at the end after the 100.00, causing me more greay hairs.
So it looks like this
20.04.2005 r141DMZ1 10.203.63.6 100
20.04.2005 r141DMZ1 10.203.63.6 100
r141DMZ1 Month_Availability 100.00
I would like to replace all the spaces regardless of how much with just one and obviously no spaces at the end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 11:28 PM
тАО04-19-2005 11:28 PM
Re: Spaces in file causing problems with my array
19.04.2005 r141DMZ1 10.203.63.6 100
20.04.2005 r141DMZ1 10.203.63.6 100
20.04.2005 r141DMZ1 10.203.63.6 100
r141DMZ1 xxxMonth_Availability xxx100.00xxxx
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 11:41 PM
тАО04-19-2005 11:41 PM
Re: Spaces in file causing problems with my array
thanks for the details.
Can you replace the
@LIST=(split/ /,($line));
with
@LIST=(split/\s+/,($line));
and try again.
But it seems you are already happy with Harry's fix.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 11:41 PM
тАО04-19-2005 11:41 PM
Re: Spaces in file causing problems with my array
--8<---
#!/usr/bin/perl
use strict;
use warnings;
unlink ;
# Use magic open
@ARGV = map { "/home1/reports/output/$_/tmpftp" } qw( ljhbdss1 lptadss1 lblmdss1 lctndss1 lpthdss1 ldbndss1 );
while (<>) {
chomp (my @LIST = split /\s+/, $_, -1);
$var=$LIST[1];
print "creating $var\n";
sleep 1;
open my $fn, ">> /tmp/tmp1/$var" or die "$var: $!";
print $fn @LIST, "\n";
close $fn;
}
-->8---
Much more readable IMHO
I removed FOA and FOT, because they're not used in the snippet
It also splits on one or more whitespace characters
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 11:59 PM
тАО04-19-2005 11:59 PM
Re: Spaces in file causing problems with my array
Global symbol "$var" requires explicit package name at ./DayWeb.pl line 12.
Global symbol "$var" requires explicit package name at ./DayWeb.pl line 13.
Global symbol "$var" requires explicit package name at ./DayWeb.pl line 15.
Global symbol "$var" requires explicit package name at ./DayWeb.pl line 15.
Execution of ./DayWeb.pl aborted due to compilation errors.
$