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.
我想从文件中删除少于 2 列的行:
awk '{ if (NF < 2) print}' test one two
有没有办法将这些行存储到变量中,然后用xargsand将其删除sed,例如
xargs
sed
awk '{ if (NF < 2) VARIABLE}' test | xargs sed -i /VARIABLE/d
我想删除少于 2 列的行
小于 2 = 删除只有一列的行
sed -r '/^\s*\S+\s+\S+/!d' file
如果您想根据条件将输入拆分为两个文件(名为“通过”和“失败”):
awk '{if (NF > 1 ) print > "pass"; else print > "fail"}' input
如果您只想过滤/删除 NF < 2 的行:
awk '(NF > 1){print}' input