除了第一列之外,如何在整个文本中使用“grep-v”或类似的东西?
我正在尝试操作一个文件,可以说:
76ers23 Philadelphia 76ers announced today that
76ers24 Lakers announced today
76ers25 blazers plays today
76ers26 celics announced today that
76ers27 Bonston has Day off
76ers28 Philadelphia 76ers announced today that
76ers29 the blazzers announced today that
76ers30 76ers Training day
76ers31 Philadelphia 76ers has a day off today
76ers32 Philadelphia 76ers humiliate Lakers
76ers33 celics announced today that
我想从第二列中删除包含术语 76ers 的所有条目,以获得:
76ers24 Lakers announced today
76ers25 blazers plays today
76ers26 celics announced today that
76ers27 Bonston has Day off
76ers29 the blazzers announced today that
76ers33 celics announced today that
我的问题是,如果我将使用grep -v "76ers"它返回null
我希望仅在第二行中使用 grep(或其他命令)。
我发现了这种复杂的方式,但这正是我想要的,但我_在第二列的开头得到了一个。
cat file|awk '{print $1}' >file1
cat file|awk '{$1="";print $0}'|tr -s ' ' | tr ' ' '_' >file2
paste file1 file2 |grep -v "_76ers"
我不是 bash 专家,所以我想会有更简单的方法。先感谢您!
回答
使用跳过第一列的正则表达式。
grep -v '^[^ ]* .*76ers' file
[^ ]* 匹配到第一个空格的所有内容。