簡體   English   中英

awk腳本消除特殊字符

[英]awk script to eliminate special characters

我的輸出如下所示

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。

除了刪除不需要的字符外,如何使用命令查找所需的字符呢? 您要的行是“行首,后跟一個-,然后是空格”。

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

這種模式提取更適合grep:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM