Linux How to cut a column from one file and paste into another in a single line command?

I would like to use the linux cut command to extract a column from a file, and then use the paste command to paste the same column into the second file. I can do this by saving the results of the cut command and then running it and the second file. But it seems to me that for this you need to be one single-line, which does not imply the preservation of intermediate results. Does anyone know what this is? Thanks.

For example, the first file may look like

date weight 1-1-2010 weight1 1-2-2010 weight2 1-3-2010 weight3 

and the second may look like

 date blood_press 1-1-2010 bp1 1-2-2010 bp2 1-3-2010 bp3 

and I would like to deduce how

 date weight blood_press 1-1-2010 weight1 bp1 1-2-2010 weight2 bp2 1-3-2010 weight3 bp3 

Needless to say, the data is much larger and more complex than that. But it gives an idea of ​​what I need to do. Thanks again.

PS For reasons too detailed to include, the join command will not work.

+4
source share
1 answer

If you can live with a tab delimiter (or other single character), you can do

 cut [column-spec] file1 | paste file2 - > file3 

Command - in the paste command, it reads stdin, which, of course, contains the lines created by cut . There is no correspondence in values; it is a straight line for the line copy and paste.

+7
source

Source: https://habr.com/ru/post/1493017/


All Articles