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
    • 最新
    • 标签
主页 / user-608047

Sistemas Libsur's questions

Martin Hope
Sistemas Libsur
Asked: 2024-09-17 02:41:42 +0800 CST

正则表达式检测两个连续的行,这些行具有相同的单词和相同的顺序,但在前导、尾随和单词之间的空格不同

  • 5

我想找到一个正则表达式或 perl 单行代码来检测两行连续的行,这些行包含相同的单词且顺序相同,但前导空格、尾随空格和单词之间的空格数量可能因行而异。正则表达式必须排除那些不匹配的行。

我使用这个正则表达式来检测相同的连续行,
^\s*(.*\S)(\s\n*\1)+$
当一行与另一行之间的空格量不同时,它会失败。

我有这个示例文本

Mary has a little lamb. The live near the mountain.
Mary has a little lamb. The live near the mountain.

vrfgrgru hfiughf iujhfuihgifughuir nuhuvhfug

Mary has  a little lamb. The live near the mountain.
  Mary has a little lamb. The live near the mountain.

 Mary has a little lamb.  The live near the mountain.
Mary has a little lamb. The live near the mountain.

fghurhg bojghirejyohi ndhguhyituhgi
gbshbsiughsf bnighriugh hurhgiurhgriu

 Elvis was the greatest singer of all time. He has 18 number one in billboard charts.
Elvis was the greatest singer  of all time. He has 18 number one in billboard charts.

sgfuhgdugusd vfjsng orjgoergo ejfio dsmnjn
fbdhsbfgdbhhbfhdsfdf

Mary has a little lamb. The live near the mountain.
 Mary has a little lamb. The live near the mountain.

gsete gerttrb oijoijoijoijoijoiojo gogoerijoi

jhoiyrei  erogjrijgtrio noifdo mkooi 

This has been the coldest winter in the last 20 years.
 This has  been the coldest winter in the  last 20 years.

无论行中有多少个空格,正则表达式都应该显示包含相同信息的连续行。

没有三个连续的并且匹配的行之间没有空行。

grep
  • 1 个回答
  • 89 Views
Martin Hope
Sistemas Libsur
Asked: 2024-04-13 01:58:41 +0800 CST

显示出现次数并计算它们之间以及最后一个之后的行数

  • 11

我有这个文件:

table_01 (id, field01, field02, field03, field04)
record_01
record_02
record_03
table_02 (id, field01, field02, field03)
record_01
table_03 (id, field01, field02, field03, field04)
record_01
record_02
table_04 (id, field01, field02, field03, field04, field04)
record_01
table_05 (id, field01, field02, field03, field04)
record_01
record_02
record_03
record_04

我想要一个脚本来显示出现单词“ table”的行,并显示它们之间的行数以及最后一次出现之后的行数。

所以输出将是:

table_01 (id, field01, field02, field03, field04)
3
table_02 (id, field01, field02, field03)
1
table_03 (id, field01, field02, field03, field04)
2
table_04 (id, field01, field02, field03, field04, field04)
1
table_05 (id, field01, field02, field03, field04)
4

到目前为止我有这个脚本:

awk '$0 ~ /table/ {if (n) print NR-1-n; n=NR}' file

其输出是:

3
1
2
1

但该脚本不显示出现“ table”的行,也不显示最后一次出现之后的行。我该如何修改它以显示缺少的内容?

text-processing
  • 4 个回答
  • 218 Views

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve