以specifc字符串开头的上线

发布于 2025-02-05 04:13:48 字数 276 浏览 3 评论 0原文

如果字符串从特定的单词开始,该如何排队?

文件:

My name
is kuku
My name
is pupu
My name
is yoyo

输出应该是:

My name is kuku
My name is pupu
My name is yoyo

我尝试了以下命令,但看我缺少一些东西...

sed s=^is=\r is=g' file

How can I take line up if string start with a specific word?

file:

My name
is kuku
My name
is pupu
My name
is yoyo

Output should be:

My name is kuku
My name is pupu
My name is yoyo

I tried the below command but look I'm missing something...

sed s=^is=\r is=g' file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北方的韩爷 2025-02-12 04:13:48

这是一个awk基于基于的解决方案,根本不需要使用任何数学,只使用内置变量,而无需进行:

input

My name
is kuku
My name
is pupu
My name
is yoyo
 

code

{m,g}awk 'ORS = ORS!=OFS ? OFS : RS' FS='^

输出

My name is kuku
My name is pupu
My name is yoyo

最冷凝的版本,如果您不关心 fs 效率,

awk 'ORS=RS<ORS?RS:" "'

输出

最冷凝的版本,如果您不关心fs效率,

Here's an awk-based solution that doesn't require doing any math at all, using only built-in variables and nothing else:

INPUT

My name
is kuku
My name
is pupu
My name
is yoyo
 

CODE

{m,g}awk 'ORS = ORS!=OFS ? OFS : RS' FS='^

OUTPUT

My name is kuku
My name is pupu
My name is yoyo

The most condensed edition, if you don't care for FS efficiency, would be

awk 'ORS=RS<ORS?RS:" "'

OUTPUT

The most condensed edition, if you don't care for FS efficiency, would be

随风而去 2025-02-12 04:13:48

awk 是您的朋友:

$awk 'NR % 2 == 1 { o=$0 ; next } { print o " " $0 }' file

来源:

https://stackoverflow.com/questions/questions/ 8545538/how-do-do-join-pairs in-a-a-a-a-a-a-a-a-a in-a-a-large-file-file-file-1亿英寸 - uses-使用

英语:

  • 通过文件迭代

  • 如果行号为奇数,
    记住它,跳过

  • 其他
    粘贴记忆的线与当前(IE偶数)线被空间分隔

    “在此处输入图像描述”

awk is your friend:

$awk 'NR % 2 == 1 { o=$0 ; next } { print o " " $0 }' file

Source:

https://stackoverflow.com/questions/8545538/how-do-i-join-pairs-of-consecutive-lines-in-a-large-file-1-million-lines-using

In English:

  • Iterate through the file

  • If the line number is odd
    remember it and skip

  • Else
    paste remembered line with the current (i.e. even) line separated by space

    enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文