Pasting files with different number of lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pasting files with different number of lines
# 1  
Old 11-30-2011
Pasting files with different number of lines

Hi all,
I tried to use the paste command to paste two files with different number of lines.
e.g.

file1
Code:
A	1
B	1
C	2
D	2

file2
Code:
A	2
B	3
C	4
D	4
E	4

and I would like to get
Code:
A	1	A	2
B	1	B	3
C	2	C	4
D	2	D	4
         	E	4

with a sort of "padding" for the missing lines and in such a way that the alignment is the same in the final file

Thank you,
# 2  
Old 11-30-2011
Code:
join -a 2 -e " " -o 1.1 1.2 2.1 2.2 file1 file2

This User Gave Thanks to shamrock For This Post:
# 3  
Old 12-01-2011
Quote:
Originally Posted by shamrock
Code:
join -a 2 -e " " -o 1.1 1.2 2.1 2.2 file1 file2

Thank you very much, Shamrock. As I understand this works if file2 has more lines than file1. What if I don't know a priori which file has more lines?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print number of lines for files in directory, also print number of unique lines

I have a directory of files, I can show the number of lines in each file and order them from lowest to highest with: wc -l *|sort 15263 Image.txt 16401 reference.txt 40459 richtexteditor.txt How can I also print the number of unique lines in each file? 15263 1401 Image.txt 16401... (15 Replies)
Discussion started by: spacegoose
15 Replies

2. Shell Programming and Scripting

Cutting a column and pasting its number

Hello Gurus, This is my first ever post here. I tried looking for similar material but came up empty handed. Apologies if this is too verbose or if I'm not using the correct formatting. I have files containing a fixed number of elements per line; separator is a single space. Each line has the... (4 Replies)
Discussion started by: stdroid
4 Replies

3. Shell Programming and Scripting

help with pasting files in filesystem

quick question.. say i have few files in D or E drive.. i want to paste them in Filesystem that is /home/vivek folder... but when i try to do that it shows some error saying "There is not enough space on the destination. Try to remove files to make space." but i think its due to authorization... (3 Replies)
Discussion started by: vivek d r
3 Replies

4. Programming

perl - calculate the number of lines from particular files

Hi, plz see the below code. here my aim is to calculate the number of lines in unprocessedData.out if this file contains 40 lines then lastly $linenum should print 40.(except blank lines) i have tried below code but it giving me the output only one. can anyone help me how to do ? ... (9 Replies)
Discussion started by: pspriyanka
9 Replies

5. Shell Programming and Scripting

pasting fields from two files into one

i have two files with contents file a 1234,abcf 2345,drft 4444,befr file b tom,3 sam,5 dog,7 i want to print first column of file b and join to file a and get output as below tom,1234,abcf sam,2345,drft dog,4444,befr (2 Replies)
Discussion started by: dealerso
2 Replies

6. Shell Programming and Scripting

pasting two files while transposing one of them

hey, I have more a structural problem. I have two input files: 1.inp: 1 2 3 a b c 2 3 4 d f g and the 2.inp 6 6 6 7 7 7 8 8 8 The goal is to get as much output files (with a name 1_2_3.dat) as lines in 1.inp are like this: 6 6 6 a 7 7 7 b 8 8 8 c (5 Replies)
Discussion started by: ergy1983
5 Replies

7. Shell Programming and Scripting

Copying and pasting columns from different files

hi all, first time posting, hoping i can get some help on this. I have about 80 text files containing text in this format: # Rg Mass Density Rcm-x Rcm-y Area Rsph/sqrt(2) # == ==== ======= ===== ===== ==== ... (9 Replies)
Discussion started by: Arlamos
9 Replies

8. Shell Programming and Scripting

Number of *.txt files which have over n lines?

Can you help me please? I know that wc -l *.txt gives you the number of lines in each file. But how can i count the files that have over n lines? (4 Replies)
Discussion started by: dark_knight
4 Replies

9. Shell Programming and Scripting

Restore files by lines number!

Hello every 1 Happy new year ;) I have a problem when i've tried to write my shell scripts.. this what i've done Actually, i would like to restore the files that i have deleted by line number for example : 1 : filename1 2: filename2 3: filename3 then i can restore them by... (8 Replies)
Discussion started by: John_Smith
8 Replies

10. UNIX for Dummies Questions & Answers

Trouble pasting multiple files together!!

Hi, I would like to paste multiple files together into one large file. I have 23 of them and I would like to link them on a common variable without writing all the file names out (like in a simple join). Each has about 28,000 columns, but only 17 rows. So the final product would be a single file... (2 Replies)
Discussion started by: etownbetty
2 Replies
Login or Register to Ask a Question