Perl Script for reading table format data from file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Script for reading table format data from file.
# 1  
Old 11-25-2011
Error Perl Script for reading table format data from file.

Hi,

i need a perl script which reads the file, content is given below. and output in new file.
Code:
 TARGET DRIVE         IO1          IO2         IO3        IO4        IO5
    ------------    ---------   ---------   ---------   ---------   ---------
    0a.1.8          266            236         179        607        337
    0a.1.7          232            202         147        504        262
    0a.1.13         257            231         175        611        319
    0a.1.12         256            227         168        603        323

i need output in new file in following format.
Code:
TARGETDRIVE : 0a.1.8 0a.1.7 ......
IO1 =	266 232 257 256
IO2 =   236 202 231 227
IO3 = 179 147 175 168
:
:
so on

Thanks,
asak
# 2  
Old 11-25-2011
Quote:
Originally Posted by asak
...
i need a perl script which reads the file, content is given below. and output in new file.
Code:
 TARGET DRIVE         IO1          IO2         IO3        IO4        IO5
    ------------    ---------   ---------   ---------   ---------   ---------
    0a.1.8          266            236         179        607        337
    0a.1.7          232            202         147        504        262
    0a.1.13         257            231         175        611        319
    0a.1.12         256            227         168        603        323

i need output in new file in following format.
Code:
TARGETDRIVE : 0a.1.8 0a.1.7 ......
IO1 =	266 232 257 256
IO2 =   236 202 231 227
IO3 = 179 147 175 168
:
:
so on

...
Code:
$
$
$ cat f23
TARGET DRIVE          IO1         IO2         IO3         IO4         IO5
------------    ---------   ---------   ---------   ---------   ---------
     0a.1.8           266         236         179         607         337
     0a.1.7           232         202         147         504         262
     0a.1.13          257         231         175         611         319
     0a.1.12          256         227         168         603         323
$
$
$
$ perl -lane 'if ($. == 1) {
                push @{$x[0]}, "$F[0]$F[1] :";
                for ($i=2; $i<=$#F; $i++) {push @{$x[$i-1]}, "$F[$i] ="}
              } elsif (!/-/) {
                for ($i=0; $i<=$#F; $i++) {push @{$x[$i]}, $F[$i]}
              }
              END {
                for ($i=0; $i<=$#x; $i++) {print "@{$x[$i]}"}
              }
             ' f23
TARGETDRIVE : 0a.1.8 0a.1.7 0a.1.13 0a.1.12
IO1 = 266 232 257 256
IO2 = 236 202 231 227
IO3 = 179 147 175 168
IO4 = 607 504 611 603
IO5 = 337 262 319 323
$
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 3  
Old 11-25-2011
Hi tyler,

i did'nt get your code, can you please explain,

Regards,
asak
# 4  
Old 11-25-2011
It simply creates and prints an array, each element of which is a reference to an array of columnar data.

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

2. Shell Programming and Scripting

Perl -- Script to re-format data

Hi, I have a file with data in the following format BOX -1.000000 -1.000000 0.000000 30.00000 14.00000 0.1000000 0.000000 0.000000 0.000000 0.000000 0.000000 CYLINDER 3.595000 2.995000 0.000000 0.5100000 2.000000 Z 0.000000 0.000000 0.000000 I want to convert these files... (1 Reply)
Discussion started by: lost.identity
1 Replies

3. Shell Programming and Scripting

Input data of a file from perl into HTML table

Hi , I need an help in perl scripting. I have an perl script written and i have an for loop in that ,where as it writes some data to a file and it has details like below. cat out.txt This is the first line this is the second line. .....Now, this file needs to be send in mail in HTML... (2 Replies)
Discussion started by: scott_cog
2 Replies

4. Shell Programming and Scripting

Represent the data in table format as in mail content

hi all, I want to Represent the data in table format in mail content sample data should be like this...but i m trying to send this table to mail using unix command...hw do i do????even i echoed the table contents ...doesnt work.... help me <table style="background-color:lightblue;">... (8 Replies)
Discussion started by: navsan
8 Replies

5. Shell Programming and Scripting

Help with perl script to output data in table format...

Hello, I need help with a perl script that will process a text file and match virtual server name to profile(s). the rest will be ignored. Virtual server name follows the word "virtual" in the begging of the line. There could be multiple profiles assigned to one virtual server. For example, ... (3 Replies)
Discussion started by: besogon
3 Replies

6. Shell Programming and Scripting

how to print out data from mysql table in perl script

I'm having trouble with this code. if i do .\read.pl -u user it prints out 2010-12-20 12:00:00 host1 <cmd>a 2010-12-20 12:00:01 host1 <cmd> <execute> 2010-12-20 12:00:02 host1 <cmd>b 2010-12-20 12:00:03 host1 <cmd>c however, if i enter .\read.pl -h host1 it should... (3 Replies)
Discussion started by: kpddong
3 Replies

7. Shell Programming and Scripting

Perl: Reading data from other file

Hi, I am writting some perl scripts for daily backup process. In which I want to pass some data/referance from another txt file. Text file contains only one column and multiple rows. I want to pass this data to variables of another perl script. e.g. Refdoc.txt file contains data as: perl1... (3 Replies)
Discussion started by: n.dba
3 Replies

8. Shell Programming and Scripting

PERL: reading 2 column data into Hash file

I am trying to read in a 2 column data file into Perl Hash array index. Here is my code. #!/usr/bin/perl -w use strict; use warnings; my $file = "file_a"; my @line = (); my $index = 0; my %ind_file = (); open(FILE, $file) or die($!); while(<FILE>) { chomp($_); if ($_ eq '') { ... (1 Reply)
Discussion started by: subhap
1 Replies

9. Shell Programming and Scripting

write a perl script or kornshell reading a two files and outputting to comma format

Hello Can someone help me to write a perl script or kornshell reading a two files and outputting to comma format. Here is the two files listofdisks.txt id, diskname, diskgroup, diskisze(GB), FC 1, CN34, GRP1, 30, FC_CN34 2, CN67, GRP5, 19, 4, VD1, GRP4, 23, FC_VD1 6, CF_D1, ... (0 Replies)
Discussion started by: deiow
0 Replies

10. Shell Programming and Scripting

Script not reading Data from oracle table properly

Hi, I have a case where i am connecting to the oracle DB and reading a column value.... Script is in production...it was running fine,,,but suddenly now some times its started giving pain.... Script runs dailly....but sometimes its reading data from Oracle DB and sometimes its not rading the... (2 Replies)
Discussion started by: Sagarddd
2 Replies
Login or Register to Ask a Question