4

when i have two files such as file A

012
658
458
895
235

and file B

1
2
3
4
5

how could they be joined in bash? The output shoudl just be

1012
2658
3458
4895
5235

really I just want to bind by column such as in R (cbind).

user3419669
  • 293
  • 2
  • 4
  • 11
  • possible duplicate of [merge file in bash by pipe](http://stackoverflow.com/questions/17847534/merge-file-in-bash-by-pipe) –  Jun 09 '14 at 09:35

4 Answers4

13

Assuming columns are in equal length in both files, you can use paste command:

paste --delimiters='' fileB fileA

The default delimiter for paste command is TAB. So '' make sure no delimiter is in place.

P.P
  • 117,907
  • 20
  • 175
  • 238
  • if i would need them to be tab delimited I could just use paste --delimiters='\t' fileB fileA? – user3419669 Jun 09 '14 at 09:49
  • In that case, you can remove delimiter altogether: `paste fileB fileA` as `\t` is the default delimiter. For space delimited: `paste -d' ' fileB fileA ` – P.P Jun 09 '14 at 09:50
2

Like this maybe:

paste -d'\0' B A

Or, if you like awk:

awk 'FNR==NR{A[FNR]=$0;next} {print $0,A[FNR]}' OFS='' A B
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
1

Using pure Bash and no external commands:

while read -u 3 A && read -u 4 B; do
    echo "${B}${A}"
done 3< File_A.txt 4< File_B.txt
konsolebox
  • 72,135
  • 12
  • 99
  • 105
0
grep "run complete" *.err | awk -F: '{print $1}'|sort > a
ls ../bam/*bam | grep -v temp | awk -F[/_] '{print $3".err"}' | sort > b 
diff <(grep "run complete" *.err | awk -F: '{print $1}'|sort) <(ls ../bam/*bam | grep -v temp | awk -F[/_] '{print $3".err"}' )
paste a b
Shicheng Guo
  • 1,233
  • 16
  • 19