小编kro*_*516的帖子

使用 Awk 删除引号(双引号或单引号)

我想删除出现在 awk 输出中的引号(双引号),如何实现

 # systool -c fc_host -v | awk '/Class Device =/{host=$4}/port_state/{print  host,$3}'   (This is my awk output sorted)
"host1" "Online"
"host2" "Online"
Run Code Online (Sandbox Code Playgroud)

下面是命令和命令输出..

# systool -c fc_host -v

  Class Device = "host1"


  Class Device path = "/sys/class/fc_host/host1"

active_fc4s         = "0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 "

fabric_name         = "0x100000051ee8aecf"

issue_lip           = <store …
Run Code Online (Sandbox Code Playgroud)

awk

10
推荐指数
1
解决办法
2万
查看次数

awk 在一行中搜索字符串并计算总数

我有类似于下面给出的示例的日志,我只是SUCCESS在日志文件中查找一个字符串并计算总数。

$ cat ansible.log
lnx-host01.tin.com | SUCCESS => {"changed": false, "ping": "pong"}
lnx-host02.tin.com | SUCCESS => {"changed": false, "ping": "pong"}
Run Code Online (Sandbox Code Playgroud)

这是一种简单明了的方法,但我想知道是否可以将awk其作为单行代码来完成,而无需传递给wc命令。

$ awk '/SUCCESS/{print $0}'  ansible.log | wc -l
66

OR

$ awk '/SUCCESS/' ansible.log| wc -l
66
Run Code Online (Sandbox Code Playgroud)

awk

4
推荐指数
1
解决办法
528
查看次数

标签 统计

awk ×2