【发布时间】:2014-02-09 04:21:10
【问题描述】:
假设我在这样的文件中有一些文本:
lorem ipsum asdf gh 12345
hello, world! asdf gh this is a test
ee asdf gh ii
请注意,每一行都包含“asdf gh”。我希望能够使用一些 shell 命令来根据该分隔符字符串对齐该文本,所以我可以这样做:
$ cat my-file | some-command
lorem ipsum asdf gh 12345
hello, world! asdf gh this is a test
ee asdf gh ii
在此示例中,我在分隔符周围添加了额外的空格,但这并不重要。也就是说,输出也可以是:
$ cat my-file | some-command
lorem ipsum asdf gh 12345
hello, world! asdf gh this is a test
ee asdf gh ii
有没有简单的方法来做到这一点?我知道column 可以分栏,但它只能使用空格或字符(不是字符串或模式)作为分隔符。
【问题讨论】:
标签: regex shell awk sed printf