【问题标题】:awk script to eliminate special characters用于消除特殊字符的 awk 脚本
【发布时间】:2015-06-13 18:27:39
【问题描述】:

我的输出如下所示

judi# *diff -C 0 $* mountYday mountTday
*** mountYday   Sat Jun 13 02:57:09 2015
--- mountTday   Sat Jun 13 02:59:49 2015
***************
*** 20 ****
- /test on /dev/vx/dsk/test/test read/write/setuid/devices/intr/largefiles/logging/xattr/onerror=panic/dev=48986a5 on Wed Apr 22 22:28:04 2015
--- 19 ----
judi#

我只需要获取以单个“-”开头的行。 输出应为

- /test on /dev/vx/dsk/test/test read/write/setuid/devices/intr/largefiles/logging/xattr/onerror=panic/dev=48986a5 on Wed Apr 22 22:28:04 2015

我可以使用 awk 消除前两行:

*# diff -C 0 $* mountYday mountTday | awk '! /mount/'*

***************
*** 20 ****
- /ora03/oradata1 on /dev/vx/dsk/GRPA056L/ora03-oradata1 read/write/setuid/devices/intr/largefiles/logging/xattr/onerror=panic/dev=48986a5 on Wed Apr 22 22:28:04 2015
--- 19 ----

如何删除以***---(正好是3 个***---)和***************(15 个字符)开头的行?我正在尝试在单个命令中使用 awk。

【问题讨论】:

    标签: awk


    【解决方案1】:

    与其删除你不想要的字符,不如用一个命令找到你想要的字符?您想要的行是“行首,后跟一个 -,然后是空格”。

    $  diff -C 0 $* mountYday mountTday | awk /- / {print $0}
    

    这种模式提取更适合grep:

    $  diff -C 0 $* mountYday mountTday | grep '^- '
    

    【讨论】:

    • 谢谢...这个工作#diff -C 0 $* mountYday mountTday | grep '^-' .. 我错过了 - 之后的空格...非常感谢 Rob
    猜你喜欢
    • 1970-01-01
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    相关资源
    最近更新 更多