AWK 脚本:如何使用 awk 删除字段分隔符
以下输出
ONGC044
ONGC043
ONGC042
ONGC041
ONGC046
ONGC047
需要从此输入得到
Medium Label Medium ID Free Blocks
===============================================================================
[ONGC044] ECCPRDDB_FS_43 ac100076:4aed9b39:44f0:0001 195311616
[ONGC043] ECCPRDDB_FS_42 ac100076:4aed9b1d:44e8:0001 195311616
[ONGC042] ECCPRDDB_FS_41 ac100076:4aed9af4:4469:0001 195311616
[ONGC041] ECCPRDDB_FS_40 ac100076:4aed9ad3:445e:0001 195311616
[ONGC046] ECCPRDDB_FS_44 ac100076:4aedd04a:68c6:0001 195311616
[ONGC047] ECCPRDDB_FS_45 ac100076:4aedd4a0:6bf5:0001 195311616
Need the following output
ONGC044
ONGC043
ONGC042
ONGC041
ONGC046
ONGC047
from this input
Medium Label Medium ID Free Blocks
===============================================================================
[ONGC044] ECCPRDDB_FS_43 ac100076:4aed9b39:44f0:0001 195311616
[ONGC043] ECCPRDDB_FS_42 ac100076:4aed9b1d:44e8:0001 195311616
[ONGC042] ECCPRDDB_FS_41 ac100076:4aed9af4:4469:0001 195311616
[ONGC041] ECCPRDDB_FS_40 ac100076:4aed9ad3:445e:0001 195311616
[ONGC046] ECCPRDDB_FS_44 ac100076:4aedd04a:68c6:0001 195311616
[ONGC047] ECCPRDDB_FS_45 ac100076:4aedd4a0:6bf5:0001 195311616
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为你想要的是:
这假设你的第一个字段每次正好是 9 个(其中 7 个是你想要的)字符。如果不是这种情况,请使用以下命令从第一个字段中删除 [ 和 ]:
I think what you want is:
This assumes that your first field is exactly 9 (7 of them are the ones you want) characters each time. If this is not the case, then use the following instead to strip off of the [ and the ] from the first field:
如果数据确实那么统一,一个非常简单的管道 to:
将为您完成。
(哦,除了前两行之外;如果需要的话,可以在管道中使用
grep ^\[
删除它们)If the data is really that uniform, a very simple pipe to:
will do it for you.
(Oh, apart from the first two lines; get rid of them with
grep ^\[
in your pipeline, if you need to)这是一个仅涉及 awk 的解决方案。这个想法是让 awk 解析所需的列并从此标记中删除不需要的方括号。唯一的“技巧”是“转义”
[
字符,以免它被理解为打开重新设置。 (我们也可以使用substr
来代替,因为括号预计作为第一个和最后一个字符)Here's a solution which only involves awk. The idea is to let awk parse the desired column and remove the undesired square brackets from this token. The only "trick" is to "escape" the
[
character lest it is understood as an opening re set. (We could also usesubstr
instead since the brackets are expected as the first and last characters)