The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
perl -write values in a file to @array in perl meghana Shell Programming and Scripting 27 06-07-2009 05:05 PM
Array length in PERL anent Shell Programming and Scripting 5 07-17-2008 04:39 PM
how to get last value in an array in perl meghana Shell Programming and Scripting 7 02-04-2008 05:12 PM
multidimensional array in perl prkfriryce Shell Programming and Scripting 9 12-01-2007 04:33 PM
split to array in perl jaganadh Shell Programming and Scripting 3 07-06-2007 05:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-26-2002
Jamison Jamison is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 5
PERL array spacing

lines in:
4,355,384 20,762,557 16,407,173 TOTAL
14,470,261 27,190,250 12,719,989 TOTAL
18,825,645 47,952,807 29,127,162 TOTAL


PERL script:

open(TOTAL,"grepTOTAL /otl/ds_metric/data_files/modem_times|");
push(@total,<TOTAL>);
close(TOTAL);

$record = join(" ", @total);
$record =~ s/TOTAL//g;
@total2 = split (/\s{2,}/, $record);
print @total2;



gives me this result.

4,355,384 20,762,557 16,407,17314,470,261 27,190,250 12,719,98918,825,645 47,952,807 29,127,16

what im looking for is this:
4,355,384 20,762,557 16,407,173 14,470,261 27,190,250 12,719,989 18,825,645 47,952,807 29,127,162

Difference : there is a space where TOTAL used to be in the latter versioin of the output line.

Ive tried a few different ways to substitue the TOTAL word but everything comes back to having no space between the numbers
in between the TOTAL word (ex: 16,407,17314,470,261 27,190,250 is what i get 16,407,173 14,470,261 27,190,250 is what i want)

can anyone lend me an idea on how to get that space in there while still subbing that TOTAL out easily?

-jamison-
  #2 (permalink)  
Old 03-26-2002
Jamison Jamison is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 5
its me again..

i have added this :

$total_record = join(" ", @total);
$total_record =~ s/TOTAL//g;
@record2 = split (/\s{1,}/, $total_record);
for (@record2) {
print $_ . "\n";
}

to the code and it prints out each element out on a new line correctly. then i can run a a print statement that puts each element on the same line.

-jamison-
  #3 (permalink)  
Old 07-17-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
Code:
open(FH,"<a");
while(<FH>){
$_=~ tr/TOTAL\n//d;
push(@arr, $_);
}
close(FH);
print join("",@arr);
  #4 (permalink)  
Old 07-17-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,510
wow, that was like 6 years ago
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0