【问题标题】:how to awk specific characters from string in windows word file如何从windows word文件中的字符串中awk特定字符
【发布时间】:2012-11-16 18:56:29
【问题描述】:

我有一个 word 文档,我只想选择以整数开头的行。我有 cygwin 并想使用 awk 命令来选择整行...

我使用的命令是 awk /n/ document1,但它正在为我拉带“n”字母的行。

例如:

129 CalledVPNTop-
GroupNumber
Char[15] Indicates the top group number of the called party.
Value range: numerals within 0-9
Can be null
130 CalledVPNGrou
pNumber
Char[10] Indicates the group number of the called party.
Value range: numerals within 0-9
Can be null
131 CalledVPNShor
tNumber
Char[10] Indicates the short number of the called party
Value range: numerals within 0-9
Can be null
132 CallingNetwork
Type
Char[10] Reserved.
Can be null
133 CalledNetwork-
Type
Char[10] Reserved.
Can be null
134 GroupCallType Char[10] Indicates the call type when the charged subscriber
is a VPN user.
The options are as follows:
l 0: On-net call
l 1: Off-net call
l Other: to be extended

我想提取以 129、130、131 等整数开头的字符,以及之后的 11 个字符。任何帮助将不胜感激...

【问题讨论】:

    标签: awk cygwin


    【解决方案1】:
    awk '/^[0-9]+/{print substr($0,length($1),11)}' your_file
    

    【讨论】:

      【解决方案2】:

      对于文本文件,我会使用awk '/^[:digit:]*/ {print $0}' document.txt

      【讨论】:

      • 我试过 awk '/^[:0-9:]*/ {print $0}' Document1.txt 但我选择了整张纸
      • 您必须使用[0-9](数字范围)或[:digit:](整组)。
      • @sarathi 是对的,您还需要将* 更改为+。我的错。
      • 不需要{print $0},这是默认操作。
      • @EdMorton,你说得对,我只是习惯于明确写出来:D
      猜你喜欢
      • 2021-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      • 2019-06-21
      • 2017-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多