AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题

问题[grep](computer)

Martin Hope
S.T.A.L.K.E.R
Asked: 2025-03-01 16:13:51 +0800 CST

Grep 保留重复的行输出到 txt

  • 6

File2.txt我正在尝试根据在 中找到的字符串比较两个文件,从中复制一行File1.txt。我想保留输出中的重复行,如 所示File3.txt。如果可能的话,相同的顺序会很好。此命令仅输出单个事件。

grep -wF -f File1.txt File2.txt > File3.txt

下面是File1.txt。

dog
dog
cat
cat
cat
mouse
snake
fish

以下是File2.txt

horse  d:\horse.fbx
lion   d:\lion.fbx
monkey d:\monkey.fbx
dog    d:\dog.fbx
cat    d:\cat.fbx

下面是File3.txt。

dog    d:\dog.fbx
cat    d:\cat.fbx

以下是所需的File3.txt

dog    d:\dog.fbx
dog    d:\dog.fbx
cat    d:\cat.fbx
cat    d:\cat.fbx
cat    d:\cat.fbx
grep
  • 3 个回答
  • 96 Views
Martin Hope
omarkn
Asked: 2024-11-29 01:08:14 +0800 CST

如何查找文件名,但只能使用 grep .html 或 .php?

  • 7

这很好用:

find . -type f -name "*dan*" | grep '.html'

但是如何向 grep 添加一个呢?使用OR? -o?

find . -type f -name "*dan*" | grep '.html' or '.php' ???
grep
  • 2 个回答
  • 148 Views
Martin Hope
Jakub Bochenski
Asked: 2024-09-26 22:33:25 +0800 CST

`grep: /var/log/syslog: 二进制文件匹配`我应该担心吗?

  • 6

当我尝试 grep syslog 时,我遇到了:

$ grep -E 'Sep.*EXT4' /var/log/syslog
[... some data ...]
grep: /var/log/syslog: binary file matches

编辑:第一次尝试使用cmp和strings,但这对UTF-8产生了错误的结果。

$ \zgrep -C 2 -Pan '\x00' /var/log/syslog* |  cat -vET
/var/log/syslog.1-8236-Sep 23 11:59:12 jakub-Latitude-5431 rtkit-daemon[1824]: Successfully made thread 11652 of process 6125 owned by '1000' RT at priority 10.$
/var/log/syslog.1-8237-Sep 23 11:59:12 jakub-Latitude-5431 rtkit-daemon[1824]: Supervising 10 threads of 7 processes of 1 users.$
/var/log/syslog.1:8238:^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@Sep 23 12:03:51 jakub-Latitude-5431 systemd-modules-load[915]: Inserted module 'lp'$
/var/log/syslog.1-8239-Sep 23 12:03:51 jakub-Latitude-5431 systemd-modules-load[915]: Inserted module 'ppdev'$
/var/log/syslog.1-8240-Sep 23 12:03:51 jakub-Latitude-5431 lvm[907]:   2 logical volume(s) in volume group "vgubuntu" monitored$
/var/log/syslog.2.gz-19151-Sep 13 17:13:03 jakub-Latitude-5431 kernel: [371517.143856] audit: type=1400 audit(1726240383.797:15759): apparmor="DENIED" operation="open" class="file" profile="snap.firefox.firefox" name="/etc/fstab" pid=389526 comm="firefox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0$
/var/log/syslog.2.gz-19152-Sep 13 17:13:03 jakub-Latitude-5431 kernel: [371517.149625] audit: type=1400 audit(1726240383.802:15760): apparmor="DENIED" operation="open" class="file" profile="snap.firefox.firefox" name="/etc/fstab" pid=389526 comm="firefox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0$
/var/log/syslog.2.gz:19153:^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@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^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@Sep 13 17:31:40 jakub-Latitude-5431 systemd-modules-load[981]: Inserted module 'lp'$
/var/log/syslog.2.gz-19154-Sep 13 17:31:40 jakub-Latitude-5431 systemd-modules-load[981]: Inserted module 'ppdev'$
/var/log/syslog.2.gz-19155-Sep 13 17:31:40 jakub-Latitude-5431 systemd-modules-load[981]: Inserted module 'parport_pc'$

我不确定这里发生了什么?我认为 syslog 包含二进制字符是不正常的。

grep
  • 1 个回答
  • 38 Views
Martin Hope
pmor
Asked: 2024-04-05 19:19:00 +0800 CST

如何仅打印匹配行的匹配(非空)部分,并且每个此类部分都在同一输出行上?

  • 6

从man grep:

-o, --only-matching
  Print only the matched (non‐empty) parts of a matching line, with each such part on a separate output line.

一个简单的问题:如何仅打印匹配行的匹配(非空)部分,并且每个此类部分都在同一输出行上?

grep
  • 2 个回答
  • 32 Views
Martin Hope
WesternGun
Asked: 2023-05-25 19:19:18 +0800 CST

Maven - 在 grep 搜索中忽略 ANSI 颜色转义字符

  • 11

我发现有时,mvn输出中的 ANSI 转义字符会阻止我使用 grep 进行搜索:

mvn | grep -P "\[INFO\]"

我必须使用"\[.*INFO.*\]"才能得到结果。

如何禁用处理 ANSI 转义字符?我认为有一些配置吗?

grep
  • 2 个回答
  • 462 Views
Martin Hope
mwfearnley
Asked: 2023-02-21 01:25:30 +0800 CST

我可以使用 grep 复制 strings 命令吗?

  • 6

我经常使用不包含该strings命令的 Windows Git Bash 环境。

是否可以使用类似grep输出特定长度以上的所有 ASCII 字符串或可打印字符的工具?

grep
  • 1 个回答
  • 29 Views
Martin Hope
dcannistraro
Asked: 2022-11-01 12:58:17 +0800 CST

有没有办法在不下载文件的情况下在域上 Grep 多个 HTML 页面?

  • 7

我本质上想在浏览器中Ctrl添加F多个站点。

我在域上有一系列 URLhttps://exampleblog.com/posts/{1-50}

我想/posts/一次 grep 下的所有页面。它们每个都用从 1 到 50 的有序 int 进行标识。

有没有办法在不下载的情况下做到这一点wget?我想 grep 我从中得到的信息curl。

我觉得有一个雄辩的管道或一个班轮可以让我从终端执行此操作而无需下载(尽管它可能很慢)。

grep pipe curl wget
  • 1 个回答
  • 46 Views
Martin Hope
eljiwo
Asked: 2022-07-02 15:29:08 +0800 CST

使用 sed 捕获进程输出,捕获文本块,然后在其中过滤

  • 5

我想用 sed 过滤一些标准输出,但我不知道如何。标准输出示例是:

.
.
.
Model a.             # This should be captured
.
.
.
Metrics results:     # This should be captured
==================== # This should be captured
metric 1             # This should be captured
metric 2             # This should be captured
metric 3             # This should be captured
==================== # This should be captured
.
.
.
Model b              # This should be captured
.
.
.
Metrics results:     # This should be captured
==================== # This should be captured
metric 1             # This should be captured
metric 2             # This should be captured
metric 3             # This should be captured
==================== # This should be captured
.
.
.

其中.表示包含任何随机字符的行。所以结果是

Model a
Metrics results:
====================
metric 1
metric 2
metric 3
====================
Model b
Metrics results:
====================
metric 1
metric 2
metric 3
====================

我可以使用什么 sed 命令?还将感谢有关如何了解 sed 的解释。

bash grep
  • 1 个回答
  • 53 Views
Martin Hope
surfmuggle
Asked: 2022-05-25 01:34:19 +0800 CST

如何对包含特定字符串的文件中的所有行进行分组和计数

  • 5

我想过滤文件中包含的所有行,mySearchString然后将它们组合在一起并计算它们。

示例查找包含的所有行9791

AB-9791___Foo
AB-9791___Foo
DE-9791___Bar
AB-0001___Foo

使用 $ grep "9791" myFile.txt给出了这个结果

AB-9791___Foo
AB-9791___Foo
DE-9791___Bar 
// 0001 was filtered out

这个结果应该像这样分组和计数(如 SQL Group by Count)

AB-9791___Foo     2
DE-9791___BAR     1

这个答案使用 perl,但我们的机器上没有安装 perl。

什么工具(grep、awk、sed或其他)可用于实现第二部分的分组和计数?

更新测试记录

在我的测试文件Test_2.txt中,这些行是写的

AB-9791___Foo
DE-9791___Bar
AB-0001___Foo
AB-9791___Foo
AB-9791___Foo
AB-9791___Foo
DE-9791___Bar
DE-9791___Bar
DE-9791___Bar

我复制并粘贴了每一AB-9791___Foo行,所以它们应该是相同的。运行$ grep '9791' Test_grep_uniq_sort.txt | uniq -c给出了这个结果

  1     AB-9791___Foo
  1     DE-9791___Bar // expected: 4 actual: 1, 2, 1
  3     AB-9791___Foo // expected: 4 actual: 1, 3
  2     DE-9791___Bar
  1     DE-9791___Bar

运行$ sort Test_2.txt > Test_2_sort_0.txt然后使用grep | uniqonTest_2_sort_0.txt几乎返回了预期的输出。

  $ grep '9791' Test_2_sort_0.txt | uniq -c
  4     AB-9791___Foo
  1     DE-9791___Bar // this is due to a missing line break / line feed
  3     DE-9791___Bar

手动添加换行符/换行符后一切正常

grep sed
  • 2 个回答
  • 338 Views
Martin Hope
Shahid
Asked: 2022-05-01 10:45:06 +0800 CST

跳过字符类中的字符

  • 5

我使用以下 grep 代码仅在 Adob​​e Indesign 中搜索单个阿拉伯字符:

\b[\x{0600}-\x{06FF}\x{0750}-\x{077F}]{1}\b
除了我只想跳过上述范围内的一个字符(即\x{0640})
之外,一切工作正常,我 无法在上面的代码中做到这一点。请建议。

regex grep
  • 1 个回答
  • 28 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve