简体   繁体   中英

combining columns of 2 files using shell script

I have one.txt

A B
C D
E F

and two.txt

H
J
N

How can I add 3rd column to one.txt like:

A B H
C D J
E F N

I want to do this using shell script .. is there any command which can help?

paste to the rescue. -d stands for "delimiter" and I set it to "space".

$ paste -d' ' one.txt two.txt
A B H
C D J
E F N

If you want the result to be stored in one.txt , you can save it in a temporary file and then replace one.txt with it:

$ paste -d' ' one.txt two.txt > temp && mv temp one.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM