How to combine 2 files into 1 file with 2 columns

Hi Guys,

I want to combine 2 files and and put together in 1 file and make two columns out it. See below desired output. Any help will be much appreciated.

inputfile1.txt

12345
67890
24580

inputfile2.txt

AAAAA
BBBBB
CCCCC

DESIRED OUTPUT:
outputfile.txt

12345     AAAAA
67890     BBBBB
24580     CCCCC

Thanks in advance!

Br,
Pinpe

paste inputfile1.txt inputfile2.txt > outputfile.txt

Hi Scrutinizer,

This is great! Thanks dude! But the output show that it has a 5 spaces in between the columns. I want to make it 1 space only as shown below.

paste inputfile1.txt inputfile2.txt > outputfile.txt

12345     AAAAA
67890     BBBBB
24580     CCCCC

DESIRED OUTPUT:

12345 AAAAA
67890 BBBBB
24580 CCCCC

Thanks again in advance.

Br,
Pinpe

paste -d" " inputfile1.txt inputfile2.txt > outputfile.txt

PS: those are not spaces that separate the columns, but TABs :wink:

#(cat t1 ; cat  t2 ) | xargs -n 2
12345 67890
24580 AAAAA
BBBBB CCCCC

@Honglus: that is not what is required..

# awk 'NR==FNR{a[i++]=$0};{b[x++]=$0;};{k=x-i};END{for(j=0;j<i;) print a[j++],b[k++]}' inputfile1.txt inputfile2.txt 
12345 AAAAA
67890 BBBBB
24580 CCCCC

regards
ygemici

 
awk 'NR==FNR{a[i++]=$0;next}{print a[j++],$0}' file1 file2
# x=1;while read -r l ; do echo "$l $(sed -n "$x p" file2)";((x++)); done<file1
12345 AAAAA
67890 BBBBB
24580 CCCCC

regdards
ygemici

awk 'getline x<f{print x$0}' f=file1 file2
awk 'getline $(NF+1)<f'=file2 file1
awk 'getline $2<f' f=file2 file1

good examples @Scrutinizer :slight_smile:
i believe these must be like below(just little correction).

awk 'getline x<f{print x,$0}' f=file1 file2
awk 'getline $(NF+1)<"file2"' file1

third is can be like this

awk 'getline $2<"file2"' file1

regards
ygemici

1 Like

@ygemici, you are correct about the first one. The second one was write in haste...

It should be:

awk 'getline $(NF+1)<f' f=file2 file1

The third one was correct...