打坏如何阅读的两个文件内容 [英] bash how to read contents of two files

查看:114
本文介绍了打坏如何阅读的两个文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此脚本从两个文件读取行,并将其输出的顺序为:

 文件1的第一行
文件2的第一行中
文件1的第二行
文件2的第二条线
等等

我如何做没有在脚本中使用外部粘贴命令?

 粘贴-d的'\\ n'文件1文件2 |而阅读一号线和放大器;&安培;读2号线;

#echo$一号线2号线$
回声$一号线
回声$ 2号线
DONE


解决方案

有关该文章Kerrek ....更新了我的code现在工作正常感谢:

  EXEC 5℃文件1
EXEC 6≤文件2
同时读取行1<&安培5安培;&安培;阅读LINE2<&安培; 6

回声$一号线
回声$ 2号线
DONE

I have this script which reads lines from two files and outputs them in order of:

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

How do I do this without using the external paste command in the script ?

paste -d'\n' file1 file2 | while read line1 && read line2;
do
#echo "$line1 $line2" 
echo "$line1" 
echo "$line2" 
done

解决方案

Thanks for that article Kerrek .... have updated my code which works fine now :

exec 5< file1
exec 6< file2
while read line1 <&5 && read line2 <&6
do
echo  "$line1"
echo "$line2"
done

这篇关于打坏如何阅读的两个文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆