common-name www.test.com.au
expiration Dec 21 01:00:31 2017 GMT
common-name www.test1.com.au
expiration Jan 19 04:41:03 2018 GMT
# Desired Output
# Field 1: Domain name
# Field 2: Date/time converted to Austraian format DD/MM/YYYY and on the same line as Domain Name.
# These will be import to excel and sort by date later.
# Repeat
Hi R Singh,
I 'd like to make change to the script for some new requirements. Hope you can give me a quick explanation how it works so i can go away and study it. Thanks
---------- Post updated at 03:39 PM ---------- Previous update was at 03:35 PM ----------
Hi Chubber_XL, sorry for a simple question but is there a way to run this code on the 1 single line instead of multiple lines.
awk '/common-name/ ##### Searching for a string "common-name" here if any line contains this in it.
{VAL=$2} ##### setting variable named VAL's value to $2 here.
/expiration/ ##### Searching for a string "expiration" here if any line contains this in it.
{num=split("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", A,","); ##### using split(built-in keyword of awk) to create an array named A, which has values of all the months Jan, Feb etc in it and mentioned separator as , in it.
for(i=1;i<=num;i++){ ##### starting a loop here which will start from i=1 to till the value of num(where num is the length of array A(which we created by split in above step)).
B[A]=i}; ##### creating an array B whose index is value of array A whose index is variable i, so it will be like B[A[1]]=B["Jan"]=1 and so on like this..
print VAL FS $3"/"B[$2]"/"$(NF-1) ##### printing the variable VAL here then mentioning FS(field seprator) which is space by default in awk. then printing values of $3"/"B[$2](where B[$2]' will be month's number)"/"$(NF-1)(is the second last field of each line, which is a year), which is date, month and year respectively.
}' Input_file ##### Mentioning the Input_file here.