Combine Multiple text or csv files column-wise


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine Multiple text or csv files column-wise
# 8  
Old 01-18-2011
Are you sure you didn't inadvertently swapped the desired result with current result? If the result of the paste is not what you want, you can pipe it to
Code:
sed 's/^\t\t*//;s/\t\t\t*/\t/g'

# 9  
Old 01-19-2011
Maybe you should add empty lines to your files (especially File3) until your file has the same number of lines than the longer one (MaxLine), before performing the paste command

Code:
MaxLine=$(wc -l File* | grep -v total | sort -k 1n | awk '{x=$1}END{print x}' )

# 10  
Old 01-20-2011
Binlib

I did not swap. The formatting got removed. The desired one is to have the output with higher records on the right stay even after pasting unlike now where it is moving over to left column.

---------- Post updated at 04:28 PM ---------- Previous update was at 04:26 PM ----------

ctsgnb

May be adding empty lines is not an option as output is coming from Oracle DB.
# 11  
Old 01-20-2011
Sorry I misread your input file. "pr -m" is your answer:
Code:
$ pr -tm <(printf "%s\n" {A..E} 6) <(printf "%s\n" {1..5}) <(printf "%s\n" x y 9 10) <(printf "%s\n" 7 8)
A          1            x              7
B          2            y              8
C          3            9              
D          4            10              
E          5                          
6


Last edited by binlib; 01-20-2011 at 09:02 PM.. Reason: Sorry, again. Not what you wanted. Now I am confused, your desired output doesn't make logical sense from your input.
# 12  
Old 01-21-2011
@venky
If these files come from Oracle DB, then you should build the SQL statement that directly generate the output in the wanted format.
# 13  
Old 01-21-2011
binlib

The columns are actually in text files. Can you give mr the exact syntax on how to combine 1.txt and 2.txt and so on to 3.txt

1.txt + 2.txt = 3.txt

---------- Post updated at 02:04 PM ---------- Previous update was at 02:01 PM ----------

ctsgnb

I am redirecting the oracle db output to text files and then want to combine the text files into a csv file. For this i am printing a comma at the end of each record. This works fine until all files have equal no. of records but when the records for file on the left is less than the file on the right then records from right side file spill over to the left.
# 14  
Old 01-21-2011
Code:
# cat t1
i
g
h

# cat t2
t
ez
z
z
z
# pr -tm -s   t*
i       t
g       ez
h       z
        z
        z
# pr -tm -s  t1 t2
i       t
g       ez
h       z
        z
        z
#

Note that after the -s option you have the (invisible) following sequence when entering the command line:
Code:
<space><cntrl>+<v><tab><space>

you can also go with :

Code:
# T=$(echo "\t")
# pr -tm -s $T t1 t2
i       t
g       ez
h       z
        z
        z

Of course you can just replace t1 t2 ... with your filenames

Last edited by ctsgnb; 01-21-2011 at 03:35 PM..
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 do I extract specific column in multiple csv files?

file1: Name,Threshold,Curr Samples,Curr Error%,Curr ART GETHome,100,21601,0.00%,47 GETregistry,100,21592,0.00%,13 GEThomeLayout,100,30466,0.00%,17 file2: Name,Threshold,Curr Samples,Curr Error%,Curr ART GETHome,100,21601,0.00%,33 GETregistry,100,21592,0.00%,22... (6 Replies)
Discussion started by: Raghuram717
6 Replies

2. Shell Programming and Scripting

Combine and complete multiple CSV files based on 1 parameter

I have to create a new CSV file based on the value listed on the 3rd column from different CSV files. This is what I need: 1. I should substitute the first column from each file, excluding the headers, with the file name InputXX. 2. Then, I need to look for rows with 0 on the third column in... (7 Replies)
Discussion started by: Xterra
7 Replies

3. Shell Programming and Scripting

Search string in multiple files and display column wise

I have 3 files. Each of those files have the same number of records, however certain records have different values. I would like to grep the field in ALL 3 files and display the output with only the differences in column wise and if possible line number File1 Name = Joe Age = 33... (3 Replies)
Discussion started by: sidnow
3 Replies

4. Shell Programming and Scripting

Row bind multiple csv files having different column headers

All, I guess by this time someone asked this kind of question, but sorry I am unable to find after a deep search. Here is my request I have many files out of which 2 sample files provided below. File-1 (with A,B as column headers) A,B 1,2 File-2 (with C, D as column headers) C,D 4,5 I... (7 Replies)
Discussion started by: ks_reddy
7 Replies

5. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

6. Shell Programming and Scripting

Insterting column in csv from multiple files

Hello, I have a spec file that contains a lot of strings that looks like this: PC DELL OptiPlex 3010MT i3 3220/2GB/500GB/DVD-RW/FREE DOS / 5Y NBD Intel i3 3220 (Dual Core, 3.30GHz, 3MB, w/ HD2500 Graphics), 2GB (1x2GB) DDR3 PC3-1600MHz, 500GB HDD SATA III 7200rpm, DVD+/-RW (16x),... (9 Replies)
Discussion started by: g9100
9 Replies

7. Shell Programming and Scripting

Column wise text adding

Hi I have pasted sample data as below:- in data.txt Please suggest any way out: as the 3rd field is cat data.txt 22:37:34 STARTING abc 22:37:40 FAILURE sadn 00:06:42 STARTING asd 00:06:51 FAILURE ad 02:06:38 STARTING acs 02:06:46 FAILURE cz 04:06:35 STARTING xzc... (1 Reply)
Discussion started by: Gaurav198
1 Replies

8. Red Hat

How to find a garbage entry in a column wise text file in Linux?

Suppose I have a file containing :- 1 Apple $50 2 Orange $30 3 Banana $10 4 Guava $25 5 Pine@apple $12 6 Strawberry $21 7 Grapes $12 In the 5th row, @ character inserted. I want through sort command or by any other way this row should either on top or bottom. By sort command garbage... (1 Reply)
Discussion started by: Dipankar Mitra
1 Replies

9. Shell Programming and Scripting

combine multiple files by column into one files already sorted!

I have multiple files; each file contains a certain data in a column view simply i want to combine all those files into one file in columns example file1: a b c d file 2: 1 2 3 4 file 3: G (4 Replies)
Discussion started by: ahmedamro
4 Replies

10. UNIX for Advanced & Expert Users

How to compare two text files in column wise?

Hi All, I have two txt files like this File1: no name ---------- 12 aaaa 23 bbbb 55 cccc File2 dname dno ------------ civil 33 mech 55 arch 66 Now i want to compare col1 from File and col2 from File2, if its match i want fetch all columns from... (3 Replies)
Discussion started by: psiva_arul
3 Replies
Login or Register to Ask a Question