¿Cómo puedo agregar el contenido de un archivo de texto al inicio de otro archivo de texto?
Hay 3 archivos llamados f1
f2
f3
. Los tres tienen algún contenido de texto.
¿Cómo puedo agregar el contenido del archivo f1
al inicio del archivo f3
y el contenido del archivo f2
al final del archivo f3
?
Respuesta1
Utilice el cat
comando. Usando su ejemplo, cat f1 f3 f2
combinará los archivos para que se lean como f1, f3 y luego f2. Sale a stdout
, por lo que si desea que f3 se lea así, redirigirá a un archivo temporal y luego moverá ese archivo a f3:cat f1 f3 f2 > tmp ; mv tmp f3
Respuesta2
Haz una dirección temporal... toca la temperatura
cat f1 >> temp .. temp now has the content of f1
cat f3 >> temp .. temp now has content of f1 and then f3
cat f2 >> temp .. temp now has the content in following order.. f1 f3 f2
mv temp f3 .. now file f3 contains f1 ..f3..f2