1

The below is the content in a file

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

I need to print vlg00457.wdf.sap.corp and sde which is in between the strings "partitions" and "to" using single awk. Right now, I was able to get with two awk separated

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
αғsнιη
  • 41,407

2 Answers2

1

Using sed:

$ grep "ERROR: Disks partitions" bala.txt |
    sed -E 's/(^.*ERROR: Disks partitions | to be checked.*$)//g'
sde
Jim L.
  • 7,997
  • 1
  • 13
  • 27
  • This will work (for the “sde” part) if the file, as shown, is a single line (with 888 characters). But those characters contain 16 occurrences of “\n”.  If those are meant to represent newlines, then it is a 16-line file, and your answer will print the first 15 lines in their entirety. – G-Man Says 'Reinstate Monica' Oct 29 '19 at 02:10
  • Thank you, @G-Man. I have improved my answer based on your feedback. – Jim L. Oct 30 '19 at 16:11
0

piece of cake with Perl:

$ perl -F\; -lane '/partitions (\S+)/ and print "$F[1]\t$1"' bala.txt