Convert array data to excel format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert array data to excel format
# 1  
Old 10-21-2010
Convert array data to excel format

I need your help in changing the script
I have data has below text file
Code:
 
:> cat my_emp
Employee array(0)
Name :  Albert
No : 1234
Address: stationstraat
City: Utrecht
Employee array (1)
Name : Kouwen
No : 1256
Address: stationstraat
City: Amsterdam
Employee array (2)
Name : Peter
No : 9256
Address: atomweg
City: Groningen
Employee array (10)
Name : Claudio
No : 9257
Address: Beatrixlaan
City: DenHaag

I wanted to convert that as below:
Desired output:
Code:
 
Name  | No| City
Alber |1234| Utrecht
Kouwen|1256| Amsterdam
Peter|9256| Groningen
Claudio|9257| DenHaag

I used the script below:
Code:
 
awk -F"= " '/Name/{if(s){print s}s=$NF}
/No/ || /City/{s=s "\t" $NF}
END{print s}' my_emp

my out put is not as expected but as here:
Actual output:
Code:
 
Name :  Albert  No : 1234       City: Utrecht
Name : Kouwen   No : 1256       City: Amsterdam
Name : Peter    No : 9256       City: Groningen
Name : Claudio  No : 9257       City: DenHaag

I am strugling to modify the script to ge my desired output,
any expert can help please?
Regards,
# 2  
Old 10-21-2010
Something like this?
Code:
awk '
/^Name/{n=$NF}
/^No/{n=n "|" $NF}
/^City/{print n "|" $NF}
' file

# 3  
Old 10-21-2010
FS is set to "= ", but that is not what is used in the input file.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert csv data to html format

I am new to html and need to convert the attached csv file data to html format ; running into issues. please assist. #!/bin/ksh echo "<html>" ; echo "<head><style> table {border-collapse: collapse;} table, td, th {border: 1px solid black;} </style></head>" echo "<title> REPORT </title>" echo... (0 Replies)
Discussion started by: archana25
0 Replies

2. UNIX for Beginners Questions & Answers

Convert text file data into XL file format

Hi i have a file containing below info and want it to put in xl format 2878042 455134 3333176 24.231979 23.81 2880246 453022 3333268 24.141338 23.81 2879677 453495 3333172 24.310986 23.81i want this data in XL file format and want that my linux system should send me that file on my mail.... (8 Replies)
Discussion started by: scriptor
8 Replies

3. 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

4. Shell Programming and Scripting

Convert data to a tabular format

How can i convert the below data to a simpler format :- cat tabular.txt User 1 Details :- First Name = Tom Middle Name = Last Name = Hanks Age = 40 Address = User 2 details :- First Name = Mike Middle Name = Last Name = Tyson Age = 50 Address = (2 Replies)
Discussion started by: lazydev
2 Replies

5. UNIX for Dummies Questions & Answers

Changing data format from column into array

I have a file containing numbers in a column like: 10.5 16.3 15.7 2.3 46.8 3.3 . . . and I was wondering if there was a way to make it show up in an array form like: 10.5 2.3 16.3 46.8 15.7 3.3 Let's say I want to make a new column every 100 values. How can I do... (8 Replies)
Discussion started by: ShiGua
8 Replies

6. Shell Programming and Scripting

perl module to convert xlsx format to xls format

Hi Folks, I have written a perl script that reads data from excel sheet(.xls) using Spreadsheet::ParseExcel module. But the problem is this module doesn't work for excel sheets with extension .xlsx. I have gone through Spreadsheet::XLSX module with which we can read from .xlsx file directly.... (1 Reply)
Discussion started by: giridhar276
1 Replies

7. Shell Programming and Scripting

Retaining the Unix CSV format in Excel format while exporting

Hi All, I have created a Unix Shell script whch creates a *.csv file and export it to Excel. The problem i am facing is that Users wants one of the AMOUNT field in comma separted values. Example : if the Amount has the value as 3000000 User wants to be in 3,000,000 format. This Amount format... (2 Replies)
Discussion started by: rawat_me01
2 Replies

8. Shell Programming and Scripting

How to convert the data into excel sheet and send mail using 'mailx' command

Hi all I have a shell script that uses a stored proc to generate output from some tables and send the same in an e-mail using mailx command. Now I need to convert the output to excel format and send e-mail. How can I achieve this. Please help me in this regard, as it's very urgent and I have been... (5 Replies)
Discussion started by: sanbabu
5 Replies

9. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies
Login or Register to Ask a Question