Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于搜索和复制的Shell脚本_Shell_Unix_Grep - Fatal编程技术网

用于搜索和复制的Shell脚本

用于搜索和复制的Shell脚本,shell,unix,grep,Shell,Unix,Grep,我不熟悉Shell脚本,这就是我所寻找的- 我需要将目录中的.gz tar文件解压缩到该目录中的临时子目录中。 我需要在这个临时目录的文件中搜索字符串模式。搜索之后,我必须将文件名和出现此字符串的对应行复制到新文件中。最后,我必须删除临时目录 欢迎任何帮助。提前感谢grep-r'foo'/bar>baz.txt 在/bar 搜索字符串foo 输出文件名和匹配行 将输出发送到baz.txt 编辑 谁没有读过这个人 SYNOPSIS grep [OPTIONS] PATTERN

我不熟悉Shell脚本,这就是我所寻找的-

我需要将目录中的.gz tar文件解压缩到该目录中的临时子目录中。 我需要在这个临时目录的文件中搜索字符串模式。搜索之后,我必须将文件名和出现此字符串的对应行复制到新文件中。最后,我必须删除临时目录

欢迎任何帮助。提前感谢

grep-r'foo'/bar>baz.txt
  • /bar
  • 搜索字符串
    foo
  • 输出文件名和匹配行
  • 将输出发送到
    baz.txt
编辑 谁没有读过这个人

SYNOPSIS grep [OPTIONS] PATTERN [FILE...] OPTIONS -R, -r, --recursive Read all files under each directory, recursively; this is equivalent to the -d recurse option. 提要 grep[OPTIONS]模式[文件…] 选择权 -R、 -R,--recursive 递归读取每个目录下的所有文件;这是 相当于-d recurse选项。
grep-r'foo'/bar>baz.txt
  • /bar
  • 搜索字符串
    foo
  • 输出文件名和匹配行
  • 将输出发送到
    baz.txt
编辑 谁没有读过这个人

SYNOPSIS grep [OPTIONS] PATTERN [FILE...] OPTIONS -R, -r, --recursive Read all files under each directory, recursively; this is equivalent to the -d recurse option. 提要 grep[OPTIONS]模式[文件…] 选择权 -R、 -R,--recursive 递归读取每个目录下的所有文件;这是 相当于-d recurse选项。
如果您使用grep找到它,那么只需将它重定向到某个文件。 这就是你所需要的:

grep 'string' *.* > output.txt

如果您使用grep找到它,那么只需将它重定向到某个文件。 这就是你所需要的:

grep 'string' *.* > output.txt
grep>>新文件处理得很好grep>>新文件处理得很好