我在多个目录中有多个文件,我需要一个 grep 命令,该命令仅当文件中存在两种模式时才能返回输出。图案类似于AccessToken和Registrationrequest。图案不在同一条线上。AccessToken可以在一行中,Registrationrequest也可以在另一行中。还要在所有目录中的所有文件中递归搜索相同的内容。
试过
grep -r "string1” /directory/file | grep "string 2”
grep -rl 'string 1' | xargs grep 'string2' -l /directory/ file
grep -e string1 -e string2
Run Code Online (Sandbox Code Playgroud)
没有任何效果
有人可以帮忙吗?
我有一个名为newfile. 这个文件的内容是:
abc
xyz
abc
Run Code Online (Sandbox Code Playgroud)
现在我想找到a以c.开头和结尾的行。我输入以下命令,但结果与我预期的不一样:
grep -E '^ac$' newfile
Run Code Online (Sandbox Code Playgroud)
此命令的问题在于,当我使用^ac$该命令时,会将其解释为以开头ac而不是开头a。
我有一个关于终端中两个进程的串联的问题。我有一个包含超过 50.000 个文件的文件夹。我使用 grep 来查找那些包含特定术语的文件:
grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files
Run Code Online (Sandbox Code Playgroud)
这给了我一个像这样的巨大列表:
/var/cqp/upload/heideko/import_files/26629.vrt
/var/cqp/upload/heideko/import_files/32862.vrt
Run Code Online (Sandbox Code Playgroud)
我需要将生成的文件复制到新文件夹中。我在想这样的事情:
grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | cp * bio_files/
Run Code Online (Sandbox Code Playgroud)
我的尝试可能没有任何意义。我刚刚从终端开始。我只想将 grep 搜索生成的文件复制到名为 bio_files 的新文件夹中。我意识到我从 grep 得到的只是文件的名称。但我想使用这些名称作为 cp 命令的输入。非常感谢任何帮助。
我无法弄清楚\在此命令中放置 的位置。
grep "^D.*\(A1|A2|A3\)$" input.txt > output.txt
Run Code Online (Sandbox Code Playgroud)
我正在搜索以 a 开头D并以 A1、A2 或 A3 结尾的每一行,它们位于该行的末尾。
我试图了解 grep 如何决定将 $ 作为正则表达式或可搜索字符。我的结果表明 grep 不一致地决定 $ 的含义。
因此,我做了一个基本的例子:
$ cat testfile
$illy
$unset
Run Code Online (Sandbox Code Playgroud)
在这里,我想看看是否可以使用正则表达式抓取以“illy”结尾的行:
$ grep 'illy$' testfile
$illy
Run Code Online (Sandbox Code Playgroud)
它似乎有效,并且将 'illy$' 标准解释为 $ 是一个正则表达式,表示“在行尾匹配此表达式”。所以我现在的想法是,grep 将 $ 解释为正则表达式标准,而不是字符串。因此,如果我想尝试 grep '$illy',那么这不应该匹配任何内容,因为它将 $ 解释为正则表达式。
然而:
$ grep '$illy' testfile
$illy
Run Code Online (Sandbox Code Playgroud)
为什么会找到这条线?这证明即使是grep 也不知道如何解释字符$。更不用说,我自己试图理解它。
我正在尝试为所有者制作一份仅具有读写权限的文件副本,然后将该文件重定向到名为$dirA. 我尝试使用此命令:
cp (ls -l ~| grep -type f-perm 600) $dirA
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
cp -R 'ls -l ~ | grep ^.-rw-/---/---' $dirA
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
cp: cannot stat 'ls -l ~ | grep ^.-rw- --- ---': No such file or directory
Run Code Online (Sandbox Code Playgroud) 我想 grep 具有 string 的变量test,但我也想确保它只会找到它test是否是一行中唯一的单词。
所以,我试过这个:
string=test
echo "test" | grep "$string$"
Run Code Online (Sandbox Code Playgroud)
我想知道是否grep知道第一部分$string(在 grep " $string $" 中)要求查找 string test,而最后一部分$(在 grep "$string $ " 中要求查找 for test,但是test行后不应有任何内容。是否grep能够区$string分为变量,仅$作为行尾的正则表达式,还是必须使用某种方式将它们区分开?
因此,以下是我运行的命令:
$ ~/Documents: touch ball.txt bool-txt bowl.txt bull.txt
$ ~/Documents: ls . | grep b..l\.txt
ball.txt
bool-txt
bowl.txt
bull.txt
Run Code Online (Sandbox Code Playgroud)
我没想到bool-txt会出现在输出中,因为我已经避开了点,但它仍然没有将其视为字面意义的点。我哪里错了?
我想在具有特定字符串的文件中进行搜索,并仅显示与该字符串完全匹配的行,但这似乎不适用于grep -w.
这只是一个示例,因为我将在脚本中搜索字符串,然后只想显示那些完全匹配的行,而不是“string-xxxx”或“string.io”。
有人有什么主意吗?
root@ubuntu-client:/var/lib/apt/lists# cat aa
aide is good
this is aide one
that is aide-common good
aide-good is not ok
hello aide-help
root@ubuntu-client:/var/lib/apt/lists#
oot@ubuntu-client:/var/lib/apt/lists# grep -w aide aa
aide is good
this is aide one
that is aide-common good
aide-good is not ok
hello aide-help
root@ubuntu-client
Run Code Online (Sandbox Code Playgroud) 使用 Ubuntu 12.04 我需要帮助复制使用grep.
我有很多 pdf 文件,所以为了过滤特定的命名文件,我使用如下的 General grep 命令。
raja@badfox:~/Desktop/mtech/M.Tech II Sem-April 2012$ grep "DESIGN OF FAULT TOLERANT SYSTEMS" *.pdf
Binary file NR-DESIGN OF FAULT TOLERANT SYSTEMS.pdf matches
Binary file R09-DESIGN OF FAULT TOLERANT SYSTEMS.pdf matches
Run Code Online (Sandbox Code Playgroud)
如何自动将搜索返回的文件复制到另一个目录?