如何将公共前缀重写为标头?

发布于 2024-10-18 10:49:41 字数 666 浏览 6 评论 0原文

假设您有一个如下所示的变更注释列表:

2011-02-21: Removed first feature to get rid of previous customer
2011-02-21: Added second feature to open up new markets
2011-02-09: Implemented hot fix to calm down angry customer
2011-02-08: Developed project into a minimal viable product
2011-02-08: Started project

可以使用标准 shell 工具将其重写为以下格式吗?

2011-02-21
  * Removed first feature to get rid of previous customer
  * Added second feature to open up new markets

2011-02-09
  * Implemented hot fix to calm down angry customer

2011-02-08
  * Developed project into a minimal viable product
  * Started project

如果是这样,怎么办?

Say you're having a list of change notes like this:

2011-02-21: Removed first feature to get rid of previous customer
2011-02-21: Added second feature to open up new markets
2011-02-09: Implemented hot fix to calm down angry customer
2011-02-08: Developed project into a minimal viable product
2011-02-08: Started project

Can this be rewritten into the following format using standard shell tools?

2011-02-21
  * Removed first feature to get rid of previous customer
  * Added second feature to open up new markets

2011-02-09
  * Implemented hot fix to calm down angry customer

2011-02-08
  * Developed project into a minimal viable product
  * Started project

If so, how?

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

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

发布评论

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

评论(2

茶底世界 2024-10-25 10:49:41

通过这个管道。

#!/bin/bash

lastprefix=""
while read prefix line
do
  if [ "$prefix" != "$lastprefix" ]
  then
    lastprefix="$prefix";
    echo ""
    echo "$prefix"
  fi
  echo "  *  $line"
done

Pipe through this.

#!/bin/bash

lastprefix=""
while read prefix line
do
  if [ "$prefix" != "$lastprefix" ]
  then
    lastprefix="$prefix";
    echo ""
    echo "$prefix"
  fi
  echo "  *  $line"
done
乖不如嘢 2024-10-25 10:49:41

这应该可以做到:

awk -F: '$1 != prev {print $1; prev = $1} {$1 = ""; print "  *" $0}' inputfile

This should do it:

awk -F: '$1 != prev {print $1; prev = $1} {$1 = ""; print "  *" $0}' inputfile
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文