gpt4 book ai didi

bash如何读取两个文件的内容

转载 作者:行者123 更新时间:2023-12-04 06:05:21 27 4
gpt4 key购买 nike

我有这个脚本从两个文件中读取行并按以下顺序输出它们:

The first line of file1
the first line of file2
the second line of file1
the second line of file2
etc

如何在不使用脚本中的外部粘贴命令的情况下执行此操作?
paste -d'\n' file1 file2 | while read line1 && read line2;
do
#echo "$line1 $line2"
echo "$line1"
echo "$line2"
done

最佳答案

使用文件描述符和 read ,例如see here .

exec 5< file1
exec 6< file2

read line1 <&5
read line2 <&6

echo -n "$line1\n$line2"

关于bash如何读取两个文件的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8423684/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com