CSV file horizontal formatting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CSV file horizontal formatting
# 1  
Old 09-20-2010
CSV file horizontal formatting

Hi folks,

Please help me with csv file formatting which needs to be done in horizontal fashion.
I have data coming in separate files every hour. What I need to do is extract three values into csv file. In the next hour, I need to extract the new values beside the three values which were extracted last hour in the same csv file. This process continues for every hour. Please find below example of the same.

File_1st_hr
server1,alarm1,1000
server2,alarm2,1001
server3,alarm3,1002

File_2nd_hr
server4,alarm4,1003
server5,alarm5,1004

File_3rd_hr
server7,alarm7,1006
server8,alarm8,1007
server9,alarm9,1008
server6,alarm6,1005

Output csv file should look like as below

0000 hrs,,,0100 hrs,,,0200 hrs
server1,alarm1,1000,server4,alarm4,1003,server7,alarm7,1006
server2,alarm2,1001,server5,alarm5,1004,server8,alarm8,1007
server3,alarm3,1002,,,,server9,alarm9,1008
,,,,,,server6,alarm6,1005

I hope my query is clear. Your inputs will be appreciated.

Thanks,
Harsha

Last edited by vharsha; 09-20-2010 at 06:08 AM..
# 2  
Old 09-20-2010
Code:
paste -d \| File_1st_hr File_2nd_hr File_3rd_hr |sed 's/^||/,,,,,,/;s/|$/,,,/;s/||/,,,/g;s/|/,/g'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert a horizontal lines to vertical lines in a csv file

Hi.. I need some help in converting the below horizontal lines to vertical lines format. can anyone help me on this. input file Hour,1,2,3,4,5 90RT,106,111,111,112,111 output file Hour,90RT 1,106 2,111 3,111 4,112 5,111 (3 Replies)
Discussion started by: Raghuram717
3 Replies

2. Shell Programming and Scripting

Data formatting in CSV file to EXCEL

Hello friends I want to convert an csv file on unix (which is generated by a ETL application) to a formatted excel sheet like .I have roughly like 28 columns 1)All numbers need to be stored as numbers with leading zeros-like format as text for this column to preserve leading zeroes e.g... (6 Replies)
Discussion started by: etldev
6 Replies

3. Shell Programming and Scripting

Help formatting a .csv file

Dear friends, please your help. I got a .csv (comma separated values) file with 61 columns I need to make a script to change the original file into a new one with this actions: Delete Columns: 1,13-20 Change the format of the following columns: 2: '2013-11-07 00:00:00' to '07/11/2013 0:00'... (5 Replies)
Discussion started by: lestatyela
5 Replies

4. Shell Programming and Scripting

Need perl or shell script to sort vertical lines to horizontal line in csv format

Need perl or shell script to sort vertical lines to horizontal line in csv format My file like below ------------------------- ================================================================================ PATH PINKY1000#I1-1-ZENTA1000-2#I7-1-ASON-SBR-UP-943113845 ... (4 Replies)
Discussion started by: sreedhargouda.h
4 Replies

5. Shell Programming and Scripting

Request for horizontal formatting code

The input file contains 4 bytes per row 1 2 3 4 5 6 7 8 9 10 11 12 * * * 108 1 2 3 4 5 6 7 8 9 10 11 12 * * * 108 I need to put them in a horizontal manner and this need to repeat after every 108 lines lso the output comes as 1 2 3 4 5 6 7 8 9 10 11 12 ..... 108 1 2... (4 Replies)
Discussion started by: necro98
4 Replies

6. Shell Programming and Scripting

Formatting csv file

Hello I wrote a perl script to output a text file filled with ip addresses and ports that i scanned into microsoft excel. Now that the data is in excel my boss wants me to organize the file in csv format such as Server,port,protocol,random,random,random ns1,25,tcp,stuff,stuff,stuff Can... (0 Replies)
Discussion started by: kingbp
0 Replies

7. Shell Programming and Scripting

Formatting csv file in Unix script

Hi, Am using the following command to create a csv file paste File_1.csv File_4.csv File_7.csv >Out1.csv paste File_2.csv File_5.csv File_8.csv >>Out1.csv paste File_3.csv File_4.csv File_9.csv >>Out1.csv Input Data: Expected Output: Column 1 Column 2 ... (2 Replies)
Discussion started by: meva
2 Replies

8. Shell Programming and Scripting

Formatting isql output to horizontal format

Hi I am formatting informix isql output(vertical) to horizontal format. Suppose I have the following content in the flat file from isql output - item_nbr 0 usfn_label Subscriber Class usfn_name SBCLASS usfn_value bl5 item_nbr 1 usfn_label Switch Name usfn_name switchName... (2 Replies)
Discussion started by: nsinha
2 Replies

9. Shell Programming and Scripting

Formatting Data - CSV

I want to check whether if any column data has any + , - , = prefixed to it then convert it in such a form that in excel its not read as formula. echo "$DATA" | awk 'BEGIN { OFS="," } -F" " {print $1,$2,$3,$4,$5,$6,$7,$8.$9,$10,$11,$12}' (4 Replies)
Discussion started by: dinjo_jo
4 Replies

10. Shell Programming and Scripting

Help with formatting a csv file

Hi, Can anyone help me format a csv file. My csv file have 6 columns. the last 2 columns were put on the second row. Here is the sample output: 000584, 200829014,30,PAPER, 4200059000,'DIXIE BOWLS HEAVY DUTY DISPOSABLE 10 OZ 1. How can I put the last 2 columns in the first row,... (1 Reply)
Discussion started by: softwood
1 Replies
Login or Register to Ask a Question