【问题标题】:How to select GID in /etc/password through Regular expression?如何通过正则表达式在 /etc/password 中选择 GID?
【发布时间】:2016-01-24 12:07:44
【问题描述】:

我想选择/etc/passwd中的GID字段。

我使用/:[0-9]\{1,\}选择UID,但不知道如何选择GID

【问题讨论】:

  • 您能告诉我如何解决吗?没有格式化。
  • 您可以尝试解析行首:^[^:]\+:\(\d\+\):\(\d\+\):,然后使用捕获组。

标签: regex bash shell vim


【解决方案1】:

GID 是第四个字段,因此您可以使用:

/\([^:]\+:\)\{3}\zs[^:]\+
 ***************###""""""

* matches the first three fields
# starts the actual match from here
" matches 1 or more non-colons

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    • 2012-06-10
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    相关资源
    最近更新 更多