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
# 1  
Old 01-17-2011
Combine Multiple text or csv files column-wise

Hi All

I am trying to combine columns from multiple text files into a single file using paste command but the record length being unequal in the different files the data is running over to the closest empty cell on the left. Please see below.
What can i do to resolve this ?
Code:
File 1		File 2		File3 		File4

A		1		X		7		
B		2		Y		8
C		3				9
D		4				10
E		5
		6

Desired Output

Final File
Code:
Column1	Column2	Column3	Column4
    A	            1	            X	            7		
    B	            2	            Y	            8
    C	            3	            9
    D	            4		   10
    E	            5
    6

Current Output
Code:
Column1	Column2	Column3	Column4
A	        1	        X	        7		
B	        2	        Y	        8
C	        3	        9
D	        4	        10
E	        5
6


Last edited by Scott; 01-17-2011 at 02:00 PM.. Reason: Code tags
# 2  
Old 01-17-2011
Your current output and desired output look same.
Also you didn't mention the inputs completely. Pls mention sample of each file content, expected out, current output, the command you are tried.
This User Gave Thanks to anurag.singh For This Post:
# 3  
Old 01-17-2011
Hi Anurag

The tabulation got removed when i put in the post. I attaching it as a text file.

I am using paste File1.txt File2.txt File3.txt File4.txt > Final File.txt

Please see attachment

Moderator's Comments:
Mod Comment The tabulation got removed because you didn't use code tags. See what happens... Smilie

Last edited by Scott; 01-17-2011 at 02:02 PM..
# 4  
Old 01-17-2011
try using the -d option of paste command to explicitly display another delimiter and check that the right number are paste in the right columns.

(maybe it is just a matter of displaying the tab key)
This User Gave Thanks to ctsgnb For This Post:
# 5  
Old 01-17-2011
I did try the '-d' option of paste command but to no respite
# 6  
Old 01-18-2011
Code:
paste File1.txt File2.txt File3.txt File4.txt

works for me. You may try:
Code:
paste -d'\t' File1.txt File2.txt File3.txt File4.txt

# 7  
Old 01-18-2011
Anurag

Not working for me. Did you try with files having different no. of records.

The problem happens when the records in the file on the right are higher than on the file on the left.

When this the case records from right side file spill over to the file on the left like below .

Code:
1  A
2  B
   C

instead of

Code:
1 A
2 B
C

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 01-18-2011 at 11:57 AM.. Reason: code tags, please!
This User Gave Thanks to venky_ibm For This Post:
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