Read from two files line by line and process them simultaneously

前端 未结 2 820
面向向阳花
面向向阳花 2020-12-12 07:33

Hello everyone I\'m very new to the game so my question is probably rather simple but I\'m stuck at this for a long time. I want to process two files from two list of files

2条回答
  •  生来不讨喜
    2020-12-12 08:31

    You need two separate file descriptors to read from two files at once. One of them can be standard input.

    while IFS= read -r line1 && IFS= read -r line2 <&3; do
      echo "File 1: $line1"
      echo "File 2: $line2"
    done < file1 3< file2
    

提交回复
热议问题