Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在多个输入源上逐个配对循环_Bash_Loops - Fatal编程技术网

Bash 在多个输入源上逐个配对循环

Bash 在多个输入源上逐个配对循环,bash,loops,Bash,Loops,要求 两个文件:A和W 需要将文件A的第一行与文件W的第一行配对;第二到第二,第三到第三 示例: >>> File A text1 text2 text3 text4 text5 text6 text7 text8 text9 >>> File W 1 2 3 4 5 6 7 8 9 我所做的: #!/bin/sh while read -r a <&3; do while read w<&4; do

要求

两个文件:A和W

需要将文件A的第一行与文件W的第一行配对;第二到第二,第三到第三

示例:

>>> File A 
text1
text2
text3
text4
text5
text6
text7
text8
text9

>>> File W 
1
2
3
4
5
6
7
8
9
我所做的:

#!/bin/sh

while read -r a <&3; do
   while read w<&4; do
       echo "add host name $a ipv4-address $w"
   done 4<W
done 3<A
我该怎么做?

试试这个-

paste a b|awk '{print "add host name " $1 " ipv4-address " $2}'
add host name text1 ipv4-address 1
add host name text2 ipv4-address 2
add host name text3 ipv4-address 3
add host name text4 ipv4-address 4
add host name text5 ipv4-address 5
add host name text6 ipv4-address 6
add host name text7 ipv4-address 7
add host name text8 ipv4-address 8
add host name text9 ipv4-address 9
试试这个-

paste a b|awk '{print "add host name " $1 " ipv4-address " $2}'
add host name text1 ipv4-address 1
add host name text2 ipv4-address 2
add host name text3 ipv4-address 3
add host name text4 ipv4-address 4
add host name text5 ipv4-address 5
add host name text6 ipv4-address 6
add host name text7 ipv4-address 7
add host name text8 ipv4-address 8
add host name text9 ipv4-address 9
您可以尝试以下操作:

file1=A
file2=W

while read -r line1 && read -r line2 <&3 ; do
  printf "add host name %s ipv4-address %s\n" "${line1}" "${line2}"
done <${file1} 3<${file2}
file1=A
文件2=W
在读取-r行1和读取-r行2时,您可以尝试以下操作:

file1=A
file2=W

while read -r line1 && read -r line2 <&3 ; do
  printf "add host name %s ipv4-address %s\n" "${line1}" "${line2}"
done <${file1} 3<${file2}
file1=A
file2=W
读取-r行1和读取-r行2时