linux - 将 grep 搜索从多个文件粘贴到一个新文件

标签 linux grep

我有多个这样的文件。

filename.log.50
filename.log.49
filename.log.48
...
...
filename.log.2
filename.log.1

所有的内容都是

....connection established
....sending data "Text"
....return ok
....connection closed

我如何将所有从 30 到 50 结尾的文件中的“发送数据“文本”行”放入一个新文件中? 我是这样一行一行地做的:

cat filename.log.50 |grep 'sending data' >> new_file.log
cat filename.log.49 |grep 'sending data' >> new_file.log
cat filename.log.48 |grep 'sending data' >> new_file.log
....
....

我在想这样的事情......

cat filename.log.5* |grep 'sending data' >> new_file.log
cat filename.log.4* |grep 'sending data' >> new_file.log
cat filename.log.3* |grep 'sending data' >> new_file.log

但这将包括 filename.log.5、filename.log.4、filename.log.3

最佳答案

我会改用循环:

for i in {30..50}; do
  grep 'sending data' "filename.log.$i"
done > new_file.log

关于linux - 将 grep 搜索从多个文件粘贴到一个新文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23832044/

相关文章:

c++ - 为什么不解决 fork 过程中的变化?

c - 通过套接字发送后文件大小发生变化

c# - 在使用 Mono 的 Ubuntu 中运行基于 DevExpress 的 ASP.NET Web 应用程序时出错

c++ - 信号处理程序和多线程

grep - 使用 grep 捕获操作系统名称

perl - grep 匹配某个模式的行,以及匹配前后的行

linux - 在 LINUX 上将 Tomcat 作为服务启动

regex - grep 或 sed 用于包含字符串的单词

python - 有什么方法可以从当前正在执行的 python 程序中逐行输出管道?

linux - 将 gzip 日志文件的特定列表通过管道传输到 zgrep