Make a table from a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Make a table from a text file
# 1  
Old 01-15-2013
Make a table from a text file

Hi,

I have a pipe separated text file.
Can some someone tell me how to convert it to a table?

Text File contents.

Code:
 
|Activities|Status1|Status2|Status3|
||NA|$io_running2|$io_running3|
|Replication Status|NA|$running2|$running3|
||NA|$master2|$master3|
|Processlist|$processlist1|$processlist2|$processlist3|
|Average|$average1|$average2|$average3|
||abc:$abc3 GB|abc:$sbc3 GB|abc:$abc3 GB|
|Sizes|efg_abc:$efg_abc3 GB|efg_abc:$efg_abc3 GB|efg_abc:$efg_abc GB|

Wants these contents to be formatted in the following tabular format.

Code:
 
table format
Activities Status1 Status2 Status3 
 
Replication Status NA $io_running2 $io_running3 
NA $running2 $running3 
NA $master2 $master3 
 
Processlist Processes:$processlist1 Processes:$processlist2 Processes:$processlist3
 
Average $average1 $average2 $average3 
 
Database Sizes abc: $abc3 abc: $abc3 abc: $abc3 
efg_abc:$efg_abc3 efg_abc:$efg_abc3 efg_abc:$efg_abc3

can anyone suggest please.

Last edited by Scott; 01-15-2013 at 05:07 AM.. Reason: Only reminder to use code tags
# 2  
Old 01-15-2013
Something like the following should work
Code:
  p perl -ne '@fields=split(/\|/,$_);shift @fields;printf "%25s", $_ for (@fields);' tmp.dat
               Activities                  Status1                  Status2                  Status3
                                                NA             $io_running2             $io_running3
       Replication Status                       NA                $running2                $running3
                                                NA                 $master2                 $master3
              Processlist            $processlist1            $processlist2            $processlist3
                  Average                $average1                $average2                $average3
                                      abc:$abc3 GB             abc:$sbc3 GB             abc:$abc3 GB
                    Sizes     efg_abc:$efg_abc3 GB     efg_abc:$efg_abc3 GB      efg_abc:$efg_abc GB

You could also do a 2 pass version throwing the data into a 2D array and working out the size of the largest field in order to determine the size of your string length in the printf statement.(left as an exercise for the reader Smilie )

Last edited by Skrynesaver; 01-15-2013 at 04:44 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make partitions in a text file?

Suppose I have a file named intro.txt and its content is as follows My name is Ankit. I am 18. I am a college student. So I want make partitions in this and store it as 1. name.txt - I am 18. 2. age.txt - I am 18. 3. student.txt -I am a college student. How do I do that in terminal? edit... (1 Reply)
Discussion started by: ANKIT ROY
1 Replies

2. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

3. UNIX for Dummies Questions & Answers

Loading text file into table

Hi, I have text file with comma seprater shown below lu8yh,n,Fri,Feb,7,2014,16:5 deer4 deer4,n,Tue,Aug,21,,2012,on r43ed r43ed,n,Tue,Nov,12,2013,12: e43sd e43sd,n,Tue,Jan,1,,2013,on, I am using below code to load the text file into table #!/bin/ksh... (16 Replies)
Discussion started by: stew
16 Replies

4. UNIX for Dummies Questions & Answers

search all file for particular text and make changes to line 3

Hi All, I am sitting on HPUX. I want to change the exit into #exit, which appears into 3red line of code in shell scripting, wondering how shell script to be called up to perform action. I have following code in all files. Now, I need to find the text exit and replace into #exit. #!/sbin/sh... (10 Replies)
Discussion started by: alok.behria
10 Replies

5. Shell Programming and Scripting

Help in script - Getting table name from a text file

hhhhhhhhhh (5 Replies)
Discussion started by: sams
5 Replies

6. Web Development

INSERT data to a Database Table from a text file

If you have a text file and if you want to Insert data to your Database Table, You can do it with these queries LOAD DATA LOCAL INFILE '/path/yourTextFile.txt' INTO TABLE yourTableName FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' (0 Replies)
Discussion started by: sitex
0 Replies

7. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies

8. Shell Programming and Scripting

how can I bcp out a table into a text file including the header row in the text file

Hi All, I need to BCP out a table into a text file along with the table headers. Normal BCP out command only bulk copies the data, and not the headers. I am using the following command: bcp database1..table1 out file1.dat -c -t\| -b1000 -A8192 -Uuser -Ppassword -efile.dat.err Regards,... (0 Replies)
Discussion started by: shilpa_acc
0 Replies

9. Shell Programming and Scripting

shellscript.query Oracle table..populate in a text file

Hi Guys, I'm new to this forum as well as to UNIX shell scripting. I'm looking for a shellscript to query an Oracle database table and populate the result set of the query in a text file. Could you someone help me out with a sample code? Thanks, Bhagat (7 Replies)
Discussion started by: bhagat.singh-j
7 Replies

10. Shell Programming and Scripting

load a data from text file into a oracle table

Hi all, I have a data like, 0,R001,2,D this wants to be loaded into a oracle database table. Pl let me know how this has to be done. Thanks in advance (2 Replies)
Discussion started by: raji35
2 Replies
Login or Register to Ask a Question