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.
我正在使用以下评论:
awk -F "\"*_\"*" '{print ";189;" $5||$4 ";-6"}' file.txt
事情是 field5 可能是 empty ,所以在这种情况下,我想显示 field4 中的内容,而不是空白空间。
但是在执行这个注释时,输出在 189 处被截断;
那么如果field5有数据,我如何打印field5,如果没有,如何打印field4?
请改用此格式:
awk -F "\"*_\"*" '{print ";189;" ($5 ? $5 : $4) ";-6"}' file.txt
另外,你真的需要两个“和*来代表-F吗?
使用三元运算符:
print ($5 ? $5 : $4)
如果$5非零且不是空字符串,它将打印$5. 否则会打印内容$4
$5
$4
如果第五个字段可能为零,那么您可以使用它:
print ($5 != "" ? $5 : $4)