【发布时间】:2018-11-21 06:29:12
【问题描述】:
我想 grep 单词“force”,但列出的大部分输出来自命令 -force。
当我执行 grep -v "-force" filename 时,它说 grep : orce 很可能是因为 -f 命令。
我只想使用 grep 从文件中查找 force 信号。怎么样?
【问题讨论】:
-
你想说你想grep“force”而不是“-force”吗?
我想 grep 单词“force”,但列出的大部分输出来自命令 -force。
当我执行 grep -v "-force" filename 时,它说 grep : orce 很可能是因为 -f 命令。
我只想使用 grep 从文件中查找 force 信号。怎么样?
【问题讨论】:
使用grep -v -- "-force" - 双重- 表示预期没有更多选项。
【讨论】:
grep -v -- "-force" | grep force
【讨论】:
【讨论】:
使用 [-] 删除特殊意义。看看这个:
> cat rand_file.txt
1. list items of random text
2. -force
3. look similar as the first batch
4. force
5. some random text
> grep -v "-force" rand_file.txt
grep: orce: No such file or directory
> grep -v "[-]force" rand_file.txt | grep force
4. force
>
【讨论】:
| grep force,因为只有第 4 行是可取的(强制信号)。