【问题标题】:Converting rows from one format to another format using linux tools [closed]使用linux工具将行从一种格式转换为另一种格式[关闭]
【发布时间】:2018-07-17 17:00:18
【问题描述】:

让我们考虑以下原始格式:

| Node[42]{id:42} | Node[208813]{id:208813} | Node[292823]{id:292823} |

是否可以使用Linux工具将其映射到:
42,208813,292823

这些数字是从[]收集的数字。
请注意,我搜索更多列的通用方法,例如:
| Node[42]{id:42} | Node[208813]{id:208813} | Node[292823]{id:292823} | Node[1]| into

42,208813,292823,1.
另请注意,{id:292823} 是可选的(不是强制性的)。

谁能帮忙?

【问题讨论】:

标签: regex linux sed grep


【解决方案1】:

使用 sed:

sed 's/[^[]*\[//;s/\][^[]*\[/,/g;s/].*//' file

输出:

42,208813,292823

请参阅:man sedThe Stack Overflow Regular Expressions FAQ

【讨论】:

    猜你喜欢
    • 2018-01-20
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多