Multicolumn csv output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multicolumn csv output
# 8  
Old 08-08-2008
Quote:
Originally Posted by summer_cherry
below one should be ok. But it supposes that there is no "|" in your file.
If not, just replace "|" with another special character which will never appear in your file.
Code:
paste -d"|" file1 file2 file3 | tr "|" "\n"

I added cut -f1,5,6 to the end of this statement, and it does a great job of recreating my original, long script with a single line-- neat!

However, it's output is still single column, like this:
Code:
A1 value value
A2 value value
B1 value value
B2 value value
C1 value value
...

I'm still looking for a way to have multicolumn output, like:
Code:
A1 value value B1 value value C1 value value ...
A2 value value B2 value value C2 value value ...
...

Thank you all for the help along the way-- paste is a great new command to use.
# 9  
Old 08-08-2008
You can add the following to the end of your command assuming that the start of the line in will start with "A" :

| awk -F',' '{if($1=="A"){printf("\n" $0)} else {printf("," $0)} }'
# 10  
Old 08-08-2008
Quote:
Originally Posted by sudhamacs
You can add the following to the end of your command assuming that the start of the line in will start with "A" :

| awk -F',' '{if($1=="A"){printf("\n" $0)} else {printf("," $0)} }'
I'm admittedly terrible at awk (though I'm starting to learn), so I just blindly copied this in, resulting in:
Code:
A1 value value A2 value value B1 value value B2 value value C1 value value ...

All the data on a single line, and the multiple time points (A1, A2, etc) next to each other.

What I'm trying to get is I fuess file1 processed into line 1, then file2 processed into line 2, etc... Typing this actually gives me an idea of how to accomplish that-- I'll reply to this thread when I try it, and see if it works.

But if anyone has an elegant way to do the trick in the meantime, I'm all ears.
# 11  
Old 08-08-2008
Ok, the fields are delimited by space rather than comma.
Try this :
| awk -F' ' '{if($1=="A"){printf("\n" $0)} else {printf(" " $0)} }'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to translate df -h output into a CSV format?

Hi, Can someone please let me know as how I can send the below df -h format of a linux system into a CSV format ? Resource Size GiB Used GiB Avail GiB Use% Cleanable GiB* ---------------- -------- -------- --------- ---- -------------- /data: pre-comp -... (10 Replies)
Discussion started by: new2prog
10 Replies

2. Shell Programming and Scripting

Save output of updated csv file as csv file itself, part 2

Hi, I have another problem. I want to sort another csv file by the first field. result.csv SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw /home/intannf/foto5/2015_0313_090651_219.JPG,0.,-7.77223,110.37310,30.75,996.46,148.75,180.94,182.00,63.92 ... (2 Replies)
Discussion started by: refrain
2 Replies

3. Shell Programming and Scripting

Save output of updated csv file as csv file itself

Hi, all I want to sort a csv file based on timestamp from oldest to newest and save the output as csv file itself. Here is an example of my csv file. test.csv SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0739.JPG,2015:02:17 11:32:21 /home/intannf/foto/IMG_0749.JPG,2015:02:17 11:37:28... (10 Replies)
Discussion started by: refrain
10 Replies

4. Shell Programming and Scripting

Output to csv contains quotes

I borrowed scripting information from thread and modified it for our environment to uuencode it and mail a csv to me. The issue I have is the output contains quotes that hinder the csv use appropriately. My script looks like this cd /tmp df -Pg | awk 'BEGIN{ print "\t\t\t SPACE OF... (8 Replies)
Discussion started by: strykergli250hp
8 Replies

5. Shell Programming and Scripting

Csv format output file using scirpt

Hi All, I get the test result file daily after running the main test script. from the resultfile, need to fetch only server info and status and put them in tabular format in a file and as well in CSV format output file. I tried using awk command but am not able to put them in tabluar... (6 Replies)
Discussion started by: Optimus81
6 Replies

6. Shell Programming and Scripting

awk math and csv output

Hi I have this list 592;1;Z:\WB\DOCS;/FS3_100G/FILER112/BU/MPS/DOCS;;;;\\FILER112\BUMPS-DOCS\;580,116,544,878 Bytes;656,561 ;77,560 592;2;Z:\WB\FOCUS;/FS3_100G/FILER112/BU/MPS/FOCUS;;;;\\FILER112\BUMPS-FOCUS\;172,430 Bytes;6 ;0 ... (12 Replies)
Discussion started by: nakaedu
12 Replies

7. Shell Programming and Scripting

compare 2 CSV fields from same diff output

Attached is a file called diff.txt It is the output from this command: diff -y --suppress-common-lines --width=5000 1.txt 2.txt > diff.txt I have also attached 1.txt and 2.txt for your convenience. Both 1.txt and 2.txt contain one very long CSV string. File 1.txt is a CSV dump of... (0 Replies)
Discussion started by: gvolpini
0 Replies

8. Shell Programming and Scripting

handling CSV file to get desired output

Hi All , i have a CSV file , pattern is given below :- Group # name # host # account # stop # # start # # check -------------------------------------------------------------------------- file format and data exmaple :- RBP2,RB0112,sihrb001,tksrb011,. ./.profile 1>/dev/null 2>&1;stop_olc_dmn... (0 Replies)
Discussion started by: deepakiniimt
0 Replies

9. Shell Programming and Scripting

format output in csv file

I am sending the output of a file to .csv file. The output should look like this: Total Customers Processed:,8 Total Customers Skipped:,0 Total Customers Added:,8 Total Customers Changed:,0 Total Policies Deleted:,0 Total Policies Failed:,0 total:,8 Now i want this output in... (1 Reply)
Discussion started by: Prashant Jain
1 Replies

10. Shell Programming and Scripting

taking output in csv file from perl

Hi, I am new to perl I need to connect from linux server to oracle database and i need to query the database and take result into csv file. i try to do but i am getting this error: #!/usr/bin/perl use DBI; BEGIN { $ENV{ORACLE_HOME} = '/home/oracle/product/8.1.7'; ... (1 Reply)
Discussion started by: prakash.gr
1 Replies
Login or Register to Ask a Question