Bir kerede bir satır döngü yaparken iç içe iki giriş dosyasından herhangi bir okumanın bir yolu olup olmadığını bilmek istedim. Örneğin, iki dosya var diyelim FileAve FileB.
Dosya:
[jaypal:~/Temp] cat filea
this is File A line1
this is File A line2
this is File A line3
FileB:
[jaypal:~/Temp] cat fileb
this is File B line1
this is File B line2
this is File B line3
Geçerli Örnek Komut Dosyası:
[jaypal:~/Temp] cat read.sh
#!/bin/bash
while read lineA
do echo $lineA
while read lineB
do echo $lineB
done < fileb
done < filea
Yürütme:
[jaypal:~/Temp] ./read.sh
this is File A line1
this is File B line1
this is File B line2
this is File B line3
this is File A line2
this is File B line1
this is File B line2
this is File B line3
this is File A line3
this is File B line1
this is File B line2
this is File B line3
Sorun ve istenen çıktı:
Bu, FileA'daki her satır için tamamen FileB üzerinden döner. Devam et, ara ver, çıkmayı denedim ama hiçbiri aradığım çıktıyı elde etmek için tasarlanmadı. Komut dosyasının File A'dan yalnızca bir satır ve FileB'den bir satır okuyup döngüden çıkmasını ve ikinci File A satırından ve B Dosyasının ikinci satırından devam etmesini istiyorum.
[jaypal:~/Temp] cat read1.sh
#!/bin/bash
count=1
while read lineA
do echo $lineA
lineB=`sed -n "$count"p fileb`
echo $lineB
count=`expr $count + 1`
done < filea
[jaypal:~/Temp] ./read1.sh
this is File A line1
this is File B line1
this is File A line2
this is File B line2
this is File A line3
this is File B line3
Bu süre loop ile elde etmek mümkün mü?
paste -d '\n' file1 file2