Looping over pairs of values in bash

前端 未结 7 2050
萌比男神i
萌比男神i 2020-11-22 03:19

I have 10 text files and I want to paste each file with its pair, such that I have 5 total files.

I tried the following:

for i in 4_1 5_         


        
7条回答
  •  长发绾君心
    2020-11-22 03:32

    the above did not work for me, but the following does read values in pairs from an ordered list

    (can be more than pairs adding extra 'read-lines' :-)

    while read x; do
      read y
      echo $x $y
    done << '___HERE'
    X1
    Y1
    X2
    Y2
    X3
    Y3
    ___HERE
    

    produces

    X1 Y1
    X2 Y2
    X3 Y3
    

提交回复
热议问题