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.
我有一个脚本文件,其中包含用空格分隔的名字、姓氏和电话号码。不是每个人都有电话号码,我想打印出有电话号码的名字。该文件看起来像这样
Andy Frey 592895 Gregory Simons 6356345 George Hillton Fredrik Thomson 125423
您可以通过以下方式轻松完成awk:
awk
[cnicutar@piper ~]$ awk 'NF==3' names Andy Frey 592895 Gregory Simons 6356345 Fredrik Thomson 125423
直接 bash:
while read -a arr do if [ -n "${arr[2]}" ] then echo ${arr[@]}; fi done < names