我想知道是否有任何方法可以一次读取一行嵌套的 while 循环中的两个输入文件。例如,假设我有两个文件FileA和FileB.
文件A:
[jaypal:~/Temp] cat filea
this is File A line1
this is File A line2
this is File A line3
Run Code Online (Sandbox Code Playgroud)
文件B:
[jaypal:~/Temp] cat fileb
this is File B line1
this is File B line2
this is File B line3
Run Code Online (Sandbox Code Playgroud)
当前示例脚本:
[jaypal:~/Temp] cat read.sh
#!/bin/bash
while read lineA
do echo $lineA
while read lineB
do echo $lineB
done < fileb
done < filea
Run Code Online (Sandbox Code Playgroud)
执行:
[jaypal:~/Temp] ./read.sh
this is File A line1
this is File B …Run Code Online (Sandbox Code Playgroud)