Looping over pairs of values in bash

前端 未结 7 2140
萌比男神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条回答
  •  Happy的楠姐
    2020-11-22 03:50

    If you want to use one variable and perform and action with it, you just need to use one loop:

    for file in 4 5 6 7 8
    do
       paste "${file}_1" "${file}_2"
    done
    

    This will do

    paste 4_1 4_2
    paste 5_1 5_2
    ...
    

提交回复
热议问题