Reading lines from two files in one while loop

前端 未结 3 1504
旧时难觅i
旧时难觅i 2020-12-03 18:01

I have a file, file1.csv containing:

This
is
some
text.

I am using while read line to cycle through each line, e.

相关标签:
3条回答
  • 2020-12-03 18:41

    Use another FD.

    while read line; do
      if ! read -u 3 line2
      then
        break
      fi
      echo "$line***$line2"
    done < file1.csv 3< file2.csv
    
    0 讨论(0)
  • 2020-12-03 18:43

    You can use the paste command:

    $ paste -d, file{1,2}.csv | while IFS=, read x y; do echo "$x:$y"; done
    This:A
    is:B
    some:C
    text.:D
    
    0 讨论(0)
  • 2020-12-03 19:00

    You could try with the paste utility:

    $ cat one
    this
    is
    some
    text
    $ cat two
    1
    2
    3
    4
    $ while read a b ; do echo $a -- $b ; done < <(paste one two)
    this -- 1
    is -- 2
    some -- 3
    text -- 4
    
    0 讨论(0)
提交回复
热议问题