根据特定图案分割线

发布于 2025-01-03 07:22:04 字数 771 浏览 0 评论 0原文

我有如下文本:

HWI-ST150_0129:2:8:19270:131483#0 chr1 735440 819383 HWI-ST150_0129:5:44:4612:112201#0 chr1 735446 819377 HWI-ST150_0129:5:61:12668:134666#0 chr1 735444 819380 

HWI-ST150_0129:2:27:6777:92418#0 chr10 107950655 107951635 HWI-ST150_0129:3:61:5129:81938#0 chr10 107950674 107951702

......

所以我们可以看到每一行都包含类似“HWI-ST150_0129:2:8:19270:131483#0 chr1 735440 819383”的模式 我希望把它变成:

HWI-ST150_0129:2:8:19270:131483#0 chr1 735440 819383
HWI-ST150_0129:5:44:4612:112201#0 chr1 735446 819377
HWI-ST150_0129:5:61:12668:134666#0 chr1 735444 819380
HWI-ST150_0129:2:27:6777:92418#0 chr10 107950655 107951635
HWI-ST150_0129:3:61:5129:81938#0 chr10 107950674 107951702

我该怎么做? bash 和 python 都可以。 我个人更喜欢bash 谢谢

I have a text like below:

HWI-ST150_0129:2:8:19270:131483#0 chr1 735440 819383 HWI-ST150_0129:5:44:4612:112201#0 chr1 735446 819377 HWI-ST150_0129:5:61:12668:134666#0 chr1 735444 819380 

HWI-ST150_0129:2:27:6777:92418#0 chr10 107950655 107951635 HWI-ST150_0129:3:61:5129:81938#0 chr10 107950674 107951702

......

So we can see each line contains the pattern like "HWI-ST150_0129:2:8:19270:131483#0 chr1 735440 819383"
I hope to make it into:

HWI-ST150_0129:2:8:19270:131483#0 chr1 735440 819383
HWI-ST150_0129:5:44:4612:112201#0 chr1 735446 819377
HWI-ST150_0129:5:61:12668:134666#0 chr1 735444 819380
HWI-ST150_0129:2:27:6777:92418#0 chr10 107950655 107951635
HWI-ST150_0129:3:61:5129:81938#0 chr10 107950674 107951702

How can I do it? Both bash and python ok.
I personally like bash more
thx

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

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

发布评论

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

评论(3

风筝在阴天搁浅。 2025-01-10 07:22:04

您使用什么语言或代码?

查找字符串中每个 HWI 的索引。
在 HWI“\r”或“\r\n”之前插入基本上是插入一个重新调整字符和换行符。

可能还想研究一下 REGEX。

What language or code are you working in?

Find the index of each HWI in the string.
The insert right before the HWI "\r" or maybe "\r\n" basically inserting a retun char and newline.

May want to look into REGEX as well.

动次打次papapa 2025-01-10 07:22:04

您没有指定工具或语言...

工具 (Windows):使用 Notepad++ 并使用以下正则表达式进行替换:

搜索:

(HWI-\w+:\d+:\d+:\d+:\d+#\d+ \w+ \d+ \d+)

替换为:

\1\n

语言(任何操作系统):使用 Perl 和给定的正则表达式。替换正则表达式应该是:

$1\n

You didn't specify a tool or language...

Tool (Windows): use Notepad++ and use the following regex for replacing:

Search:

(HWI-\w+:\d+:\d+:\d+:\d+#\d+ \w+ \d+ \d+)

Replace with:

\1\n

Language (any OS): use Perl and the given regexes. The replace regex should be:

$1\n
≈。彩虹 2025-01-10 07:22:04

这将为您提供准确的结果

 <?php
    $text ="HWI-ST150_0129:2:8:19270:131483#0 chr1 735440 819383 HWI-ST150_0129:5:44:4612:112201#0 chr1 735446 819377 HWI-ST150_0129:5:61:12668:134666#0 chr1 735444 819380 HWI-ST150_0129:2:27:6777:92418#0 chr10 107950655 107951635 HWI-ST150_0129:3:61:5129:81938#0 chr10 107950674 107951702";
    $arrHw = explode('HWI',$text);

    for($i=1;$i<count($arrHw);$i++):
        echo "HWI".$arrHw[$i]."<br/>";
    endfor;
    ?>

This will give you the exact result

 <?php
    $text ="HWI-ST150_0129:2:8:19270:131483#0 chr1 735440 819383 HWI-ST150_0129:5:44:4612:112201#0 chr1 735446 819377 HWI-ST150_0129:5:61:12668:134666#0 chr1 735444 819380 HWI-ST150_0129:2:27:6777:92418#0 chr10 107950655 107951635 HWI-ST150_0129:3:61:5129:81938#0 chr10 107950674 107951702";
    $arrHw = explode('HWI',$text);

    for($i=1;$i<count($arrHw);$i++):
        echo "HWI".$arrHw[$i]."<br/>";
    endfor;
    ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文