Put data in tabular form..


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Put data in tabular form..
# 1  
Old 06-14-2012
Put data in tabular form..

Dear Friends,
I have a file as under :

Code:
     +++ ME 12-06-13 18:16:20 
A  RED FEW AND ROW1 1MN FEL  AS
   HI FI BV      LR     TS    HR    ES    MR    
       *  0      13296   0    120   1     15
   KS  RR   
   10   0

      +++ ME 12-06-13 18:26:20 
A  RED FEW AND ROW2 1MN FEL  AS
   HI FI BV      LR     TS    HR    ES    MR
       *  1      13296   0    120   0     15
   KS  RR
   10   0

I am required to get the output as under:
Code:
 NAME	   DATE	   TIME    HI FI BV      LR     TS    HR    ES    MR   KS  RR
   ROW1 12-06-13 18:16:20     *  0      13296    0    120   1     15   10   0
   ROW2 12-06-13 18:26:20     *  1      13296    0    120   0     15   10   0

I am totally out of thought how it can be done.

Please help. Thanks in Advance.
# 2  
Old 06-15-2012
Is your file already tab-delimited?
Here a straight bit of code:
Code:
#!/usr/bin/awk -f

BEGIN{
	OFS="| ";print "NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR"
}
/\+\+\+/{
	s=$3 OFS $4
	getline
	s=$5 OFS s
	getline;getline; gsub("\t",OFS); s=s $0
	getline;getline; gsub("\t",OFS); s=s $0
	print s
}

Usage : save this code with a filename, set +x flag; then use:~/unix.com$ filename your_data_file | column -ts'|'

Last edited by tukuyomi; 06-15-2012 at 06:27 PM..
This User Gave Thanks to tukuyomi For This Post:
# 3  
Old 06-16-2012
MySQL

Quote:
Originally Posted by tukuyomi
Is your file already tab-delimited?
Here a straight bit of code:
Code:
#!/usr/bin/awk -f

BEGIN{
	OFS="| ";print "NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR"
}
/\+\+\+/{
	s=$3 OFS $4
	getline
	s=$5 OFS s
	getline;getline; gsub("\t",OFS); s=s $0
	getline;getline; gsub("\t",OFS); s=s $0
	print s
}

Usage : save this code with a filename, set +x flag; then use:~/unix.com$ filename your_data_file | column -ts'|'
Perfect!!!!!!

$ cat e1f | awk 'BEGIN {OFS="| ";print "NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR"} /\+\+\+/ {s=$3 OFS $4;getline;s=$5 OFS s;getline;getline;gsub("\t",OFS);s=s $0;print s}'
NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR
ROW1| 12-06-13| 18:16:20 * 0 13296 0 120 1 15
ROW2| 12-06-13| 18:26:20 * 1 13296 0 120 0 15

$ cat e1f | awk 'BEGIN {OFS="| ";print "NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR"} /\+\+\+/ {s=$3 OFS $4;getline;s=$5 OFS s;getline;getline;gsub ("\n",OFS);s=s $0;print s}'
NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR
ROW1| 12-06-13| 18:16:20 * 0 13296 0 120 1 15
ROW2| 12-06-13| 18:26:20 * 1 13296 0 120 0 15

$ cat e1f | awk 'BEGIN {OFS="| ";print "NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR"} /\+\+\+/ {s=$3 OFS $4;getline;s=$5 OFS s;getline;getline;gsub ("",OFS);s=s $0;print s}'
NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR
ROW1| 12-06-13| 18:16:20| | | | | | | *| | | 0| | | | | | | 1| 3| 2| 9| 6| | | | |
0| | | | | 1| 2| 0| | | | 1| | | | | | 1| 5|
ROW2| 12-06-13| 18:26:20| | | | | | | *| | | 1| | | | | | | 1| 3| 2| 9| 6| | | | |
0| | | | | 1| 2| 0| | | | 0| | | | | | 1| 5|

$ cat e1f | awk 'BEGIN {OFS="| ";print "NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR"} /\+\+\+/ {s=$3 OFS $4;getline;s=$5 OFS s;getline;getline;gsub (" ",OFS);s=s $0;print s}'
NAME| DATE| TIME| HI| FI| BV| LR| TS| HR| ES| MR| KS| RR
ROW1| 12-06-13| 18:16:20| | | | | | *| | 0| | | | | | 13296| | | | 0| | | | 120| | | 1| | | | | 15
ROW2| 12-06-13| 18:26:20| | | | | | *| | 1| | | | | | 13296| | | | 0| | | | 120| | | 0| | | | | 15

gsub changes the output format completely. Is this normal. How to put single delimiter | after each field.

Last edited by vanand420; 06-17-2012 at 11:20 AM.. Reason: New Findings
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Required to get out put of log in tabular format in email body

Dears Please support I have out put in text file and look like below fixed inquiries - Click on MAX suffix http://server:port/app User Details http://server:port/app Audit User Detail Action hhttp://server:port/app fixed inquiries - Click on MAX suffix http://server:port/app User Details ... (13 Replies)
Discussion started by: mirwasim
13 Replies

2. Shell Programming and Scripting

Fetching the required data out of a tabular form

Hello Gurus, I am trying to fetch a required number of lines from an output of a command which is in tabular form. Below is the command for reference along with how the result is being shown on UNIX shell. /usr/openv/volmgr/bin/vmquery -b -p 5 The result of the above command is as... (6 Replies)
Discussion started by: Ali Sarwar
6 Replies

3. Shell Programming and Scripting

Dispaying output in tabular form

hi, I have a script which is dispaying the output as below: Column 3:value1 Column 4:value 4 column 8:value 8 column 9:value 9 column 13:value 13 Column 3:value10 Column 4:value 40 column 8:value 80 column 9:value 90 column 13:value 103 However,I need the output in tabular... (5 Replies)
Discussion started by: Vivekit82
5 Replies

4. Shell Programming and Scripting

Displaying log file pattern output in tabular form output

Hi All, I have result log file which looks like this (below): from the content need to consolidate the result and put it in tabular form 1). Intercomponents Checking Passed: All Server are passed. ====================================================================== 2). OS version Checking... (9 Replies)
Discussion started by: Optimus81
9 Replies

5. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

6. Shell Programming and Scripting

Transpose Data form Different form

HI Guys, I have data in File A.txt RL03 RL03_A_1 RL03_B_1 RL03_C_1 RL03 -119.8 -119.5 -119.5 RL07 RL07_A_1 RL07_B_1 RL07_C_1 RL07 -119.3 -119.5 -119.5 RL15 RL15_A_1 RL15_C_1 RL15 -120.5 -119.4 RL16... (2 Replies)
Discussion started by: asavaliya
2 Replies

7. UNIX for Dummies Questions & Answers

Put data into tabular form

Hi I am having a file which is required to be presented in the under-noted output form. Please suggest. Input: Kapil: apple 4 banana 6 cherry 0 Manoj: apple 13 banana cheery 2 Output: apple banana cherry Kapil: 4 6 0 Manoj: 13 2 Thanks in... (4 Replies)
Discussion started by: vanand420
4 Replies

8. Shell Programming and Scripting

Tabular form in shell script

hi, I need to mention the data in tabular form in shell script. :confused: Input as below: Health check (heading1) CPU/Memory Utilization of pc on server (h2) 1214 of rpc3 is exceeds 0.3 % (data) CPU Utilization is normal for rpc/33 on 2673 CPU Utilization is normal for rpc/33 on... (2 Replies)
Discussion started by: sreelu
2 Replies

9. UNIX for Dummies Questions & Answers

How to read tabular data?

Hello, I have a log file which contains data in tabular format(3 columns(total, posted, rejected) and 2 rows(close, total)) as below. TOTAL POSTED REJECTED CLOSE 3 3 0 TOTAL 3 3 0 I have to search for all Total... (1 Reply)
Discussion started by: akash028
1 Replies

10. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies
Login or Register to Ask a Question