I am running a for loop against set of servers to find the cert expiry. Output of the cert command will be below for each server:line 1line 2line 3Valid From: Tuesday, 29 September 2015 10:40:13 AM To: Friday, 28 September 2018 10:40:13 AMline 5Goal is to extract only date part after To:I was able to get this working with following commandsed -n -e '/Valid/ s/.*\, *//p' |awk '{print $1   $2   $3 }')But the problem is it is printing only the last occurence ignoring all the occurences of ValidHere is the for loop I am runningfor host in `cat /home/MO/server.txt`dofor qmgr in $(ssh musr@$host dspmq)docertexp=$(ssh musr@$host <cert command> <path to cert> |sed -n -e '/Valid/ s/.*\, *//p' |awk '{print $1   $2   $3 }')echo $host     :       $qmgr      :       $certexp > out.txtdonedonethe output file is print only from the last server in the server.text file.Idea was to have a file with host name, qmgr name and cert expiry date, sort it by date and then take action.
extract part of the text from all matching lines
sed;awk;string;for