Cómo fusionar dos archivos línea por línea en Bash

Resuelto semteu asked hace 13 años • 5 respuestas

Tengo dos archivos de texto, cada uno de ellos contiene información por línea como esa.

file1.txt            file2.txt
----------           ---------
linef11              linef21
linef12              linef22
linef13              linef23
 .                    .
 .                    .
 .                    .

Me gustaría fusionar estos archivos línea por línea usando un script bash para obtener:

fileresult.txt
--------------
linef11     linef21
linef12     linef22
linef13     linef23
 .           .
 .           .
 .           .

¿Cómo se puede hacer esto en Bash?

semteu avatar Sep 28 '10 01:09 semteu
Aceptado

Puedes usar paste:

paste file1.txt file2.txt > fileresults.txt
Mark Byers avatar Sep 27 '2010 18:09 Mark Byers

aquí hay métodos sin pegar

awk

awk 'BEGIN {OFS=" "}{
  getline line < "file2"
  print $0,line
} ' file1

Intento

exec 6<"file2"
while read -r line
do
    read -r f2line <&6
    echo "${line}${f2line}"
done <"file1"
exec 6<&-
ghostdog74 avatar Sep 28 '2010 01:09 ghostdog74

Intenta seguir.

pr -tmJ a.txt b.txt > c.txt
vtha avatar Feb 01 '2013 13:02 vtha

Controlar

man paste

posible seguido de algún comando como untabifyotabs2spaces

Christopher Creutzig avatar Sep 27 '2010 18:09 Christopher Creutzig