linux - bash cut columns to one file and save onto the end of another file -
i cut 2 columns 1 file , stick them on end of second file. 2 file have exact same number of lines
file1.txt 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 file2.txt b c d e f g h j b c d e f g h j b c d e f g h j b c d e f g h j
so far have been using
cut -f9-10 file2.txt | paste file1.txt - > file3.txt
which outputs want
1 2 3 4 5 6 7 8 9 10 j 1 2 3 4 5 6 7 8 9 10 j 1 2 3 4 5 6 7 8 9 10 j
however don't want have make new file prefer alter file 1 above. i've tried
cut -f9-10 file2.txt | paste file1.txt -
but prints on screen. there way of adding columns 9 , 10 end of file1.txt?
use sponge
moreutils! allows soak standard input , write file
. is, replace file in-place after pipe.
cut -f9-10 file2.txt | paste file1.txt - | sponge file1.txt
note can doing using paste
process substitution.
$ paste -d' ' file1.txt <(awk '{print $(nf-1), $nf}' file2.txt) | sponge file1.txt $ cat file1.txt 1 2 3 4 5 6 7 8 9 10 j 1 2 3 4 5 6 7 8 9 10 j 1 2 3 4 5 6 7 8 9 10 j
this joins file1.txt
2 last columns file2.txt
using ' '
delimiter.
Comments
Post a Comment