小编use*_*010的帖子

Shell脚本 - 读取两行文件并读取另一行文件的一行

说,我有两个文件.

File1包含:

line1
line2
line3
line4
line5
line6
line7
line8
line9
line10
Run Code Online (Sandbox Code Playgroud)

和File2包含:

anotherline1
anotherline2
anotherline3
Run Code Online (Sandbox Code Playgroud)

我想做一个while循环,以便将它输出到File3:

line1
line2
anotherline1
line3
line4
anotherline2
line5
line6
anotherline3
line7
line8
anotherline1
line9
line10
anotherline2
Run Code Online (Sandbox Code Playgroud)

我在这里搜索了一个答案,但我无法弄清楚如何去做.我必须说我在shell脚本中非常棒!

另外:"while循环"应该是到达file1的结尾.无论File2有多长,实际上,在我的个人场景中,File2总是比File1短.输出应为:File1Line1,File1Line2,File2Line1,File1Line3,File1Line4,File2Line2 ....等

有帮助吗?

注意:如果之前已经回答过,那么mods请关闭这个问题.谷歌搜索几个小时后我找不到任何答案.

编辑:添加了何时结束循环的说明.

shell

6
推荐指数
1
解决办法
935
查看次数

标签 统计

shell ×1