简体   繁体   中英

joining text file with cat and bash

so, i have two text file containing

title1
title2

stored in title.txt

and

data1
data2

stored in data.txt

and i'd like to join it with cat , so it gonna look like this

title1 | data1
title2 | data2

but, the regular cat title.txt data.txt > out.txt turns the out.txt file into

title1
title2
data1
data2

i need help on using the cat so the file can look like this:

title1 | data1
title2 | data2

any answer will be appreciated

Thanks

Try saying:

paste -d'|' title.txt data.txt

For your input, it should return:

title1|data1
title2|data2

Use while loop to read from both

while IFS= read -r line && IFS= read -r line1 <&3;
     do         
        title=`echo -ne $line`;
        data=`echo -ne "$line1"`;
        echo "$title | $data" > output.txt              
     done <data.txt" 3<title.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