storing the result of grep in a separate file

我与影子孤独终老i 提交于 2020-01-30 11:28:26

问题


I am searching something logs at the following directory

$ cd opt/app/abc/logs

Now the logs folder contains many different logs like

abc.log
def.log
wer.log

Now I need to search something in logs that I am doing n the following way as I wanted to know the names of the files first in which that entry is , Let say I am searching string 456

$bash
$  cd opt/app/abc/logs
$ grep -l 456 *

now I also want that it should store all the records of string 456 in a separate text file at the same location so that after that I can open that file to see the results sum up of string 456. How to achieve this?


回答1:


Just output the command to a file:

grep -l 456 * > somefile.txt

You can do this for any command.




回答2:


Is this what you're looking for?

grep '456' * > outfile


来源:https://stackoverflow.com/questions/19754415/storing-the-result-of-grep-in-a-separate-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!