下面是文件中的内容
SM Filesystems - ci240min;vlg00457.wdf.sap.corp;00205495930028250313;;Virtual_Gcp,Virtual,SISM_responsible,Linux_Suse,Linux,E2E_Services,Database,DLM;;;;0;warning;OK: all local filesystems are writeable OK: /var is mounted with correct options \nOK: /home is mounted with correct options \nOK: /opt/bmc mounted and writeable \nOK: /boot disk usage 18% of 250M with available size of 195 MB\nOK: / disk usage 69% of 7.9G with available size of 2522 MB\nOK: /var disk usage 31% of 2.0G with available size of 1406 MB\nOK: /opt disk usage 43% of 4.0G \nOK: /tmp disk usage 4% of 2.0G with available size of 1945 MB\nOK: Found no max. files in any monitored directory \nOK: /boot/ inode usage 1% \nOK: / inode usage 45% \nOK: /var/ inode usage 4% \nOK: /opt/ inode usage 4% \nOK: /tmp/ inode usage 1% \nOK: Initialised Physical disks are in use \nERROR: Disks partitions sde to be checked \n
我需要使用 single 打印vlg00457.wdf.sap.corp
and sde
which 位于字符串“partitions”和“to”之间awk
。现在,我能够和两个awk
分开的人在一起
cat bala.txt | grep -i "ERROR: Disks partitions" | tail -1 | awk -F ";" '{print $2}'
vlg00457.wdf.sap.corp
cat bala.txt | grep -i "ERROR: Disks partitions" | tail -1 | awk -F"partitions" '/partitions/{print $2}'
sde to be checked \n
答案1
使用sed
:
$ grep "ERROR: Disks partitions" bala.txt |
sed -E 's/(^.*ERROR: Disks partitions | to be checked.*$)//g'
sde
答案2
使用 Perl 小菜一碟:
$ perl -F\; -lane '/partitions (\S+)/ and print "$F[1]\t$1"' bala.txt