示例文件test.txt
12-3 34r5 2324 - 23ed423 2322
3-4 2-32 45 34ed - 232
e-r 34-2 234 232de - 232
23-4 23-2 232 - - 232de
- - - - - -预期的结果是
12-3 34r5 2324 - 23ed423 2322条件是,应该从文件中移除第5列上包含hypen“-”的行。可以使用sed或awk吗?
我试过像awk '{print $5}' test.txt|grep '-'|xargs sed -i -e /-/d这样的东西,但没有起作用
发布于 2020-09-18 09:03:17
你能试一下吗。
awk '$5=="-"{next} 1' Input_file > temp && mv temp Input_file或
awk '$5!="-"' Input_file > temp && mv temp Input_file解释:--当-在第5个字段中找到或在第二个解决方案中找到时,只需将光标移到下一个位置,只需打印那些在其第5个字段中没有-的行。
https://stackoverflow.com/questions/63952613
复制相似问题