如何用 ||| 替换仅包含 -------- 的行
我有这样的事情:
------------------------------------------------------------------------
r2 | username | 2011-01-16 16:52:23 +0100 (Sun, 16 Jan 2011) | 1 line
Changed paths:
D /foo
Removed foo
------------------------------------------------------------------------
r1 | username | 2011-01-16 16:51:03 +0100 (Sun, 16 Jan 2011) | 1 line
Changed paths:
A /foo
created foo
------------------------------------------------------------------------
我的目标是识别在特定日期由“用户名”添加的文件。因此,我需要组合(用户名,2011 年 1 月 16 日,A)以确保它是正确的文件,然后打印 foo。 我的想法是:
- 删除空格
- 将换行符更改为 |
- 摆脱 -------------- 并用换行符替换它们,
但问题是我无法替换 ------- 因为它们与其他字符混合。
----------------------------------------------------------------------
|r2|username|2011-01-1616:52:23+0100(Sun,16Jan2011)|1line|Changedpaths:|D/foo|Removedfoo|
------------------------------------------------------------------------
|r1|username|2011-01-1616:51:03+0100(Sun,16Jan2011)|1line|Changedpaths:|A/foo|createdfoo|
------------------------------------------------------------------------
所以我认为首先用像 ||| 这样的特殊字符替换 -------------- 是个好主意。然后使用 awk FS=||| 通过换行符更改此字符OFS=\n 谁能帮助我! 谢谢
I have something like:
------------------------------------------------------------------------
r2 | username | 2011-01-16 16:52:23 +0100 (Sun, 16 Jan 2011) | 1 line
Changed paths:
D /foo
Removed foo
------------------------------------------------------------------------
r1 | username | 2011-01-16 16:51:03 +0100 (Sun, 16 Jan 2011) | 1 line
Changed paths:
A /foo
created foo
------------------------------------------------------------------------
My target is to identify the file added by the "username" in a specific date. Thus, I need to have the combination (username, 16 Jan 2011, A) to insure that it is the right file ands then print foo.
My idea is to:
- delete the white spaces
- change the newlines into |
- get rid of the --------------- and replace them with newlines
but the problem is that I couldn't replace the ------- since they are mixed with other characters.
----------------------------------------------------------------------
|r2|username|2011-01-1616:52:23+0100(Sun,16Jan2011)|1line|Changedpaths:|D/foo|Removedfoo|
------------------------------------------------------------------------
|r1|username|2011-01-1616:51:03+0100(Sun,16Jan2011)|1line|Changedpaths:|A/foo|createdfoo|
------------------------------------------------------------------------
So I thought it would be a good idea to start by replacing the --------------- by a special character like ||| and then change this character by a newline using awk FS=||| OFS=\n
Can anyone help me!
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面怎么样,
如果对输入数据执行以下操作,
则输出
希望有帮助,
——卢克
How about the following,
If the following is executed on the input data,
the output is
Hope that helps,
- Luke
输出
Output