Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个文本文件:
A1 A2 B1 B2
我使用脚本一一读取值
cat $TXT | while read FILE do DATA1=`(echo $FILE | cut -d' ' -f1)` DATA2=`(echo $FILE | cut -d' ' -f2)` done
但是 DATA2 将读取额外的 \n 字符示例:DATA2 = A2\n。
如何在不获取额外字符的情况下读取数据?
非常感谢。
while read DATA1 DATA2 REST do # DATA1 and DATA2 are already set now done < "$TXT"
这具有额外的优势,即每行输入产生的进程更少。也就是说,我的方式产生零进程,而你的方式产生 4N + 1 之类的东西。