Reputation: 61
I want to parse a really huge log file, here a example shortcut:
===== fspCIV0
/vol/vol0 -sec=sys,rw=fspsanp42.net,root=fspsanp42.net,nosuid
===== fcvCIS01
/vol/ARDW -sec=sys,rw
/vol/ARDW -sec=sys,rw
/vol/ARDW -sec=sys,rw,nosuid
/vol/ARDW -sec=sys,rw
/vol/ARDW -sec=sys,rw=none
/vol/lonulixda -sec=sys,rw=fcvsan10.net:fcvsan11.net,root=fcvsan10.net:fcvsan11.net
it continues that way for a few more pages...
The desired output should be:
vFiler, Type, host
fspCIV0, /vol/vol0, fspsanp42.net
fcvCIS01, /vol/lonulixda, fcvsan10.net
fcvCIS01, /vol/lonulixda, fcvsan11.net
The vFiler line always starts with a '=====' followed by a string after this every other line starts with '/vol/...' which is meant to be the Type, so far I already managed to get the information, but the real problem starts with the server names who are listed after 'rw= or ro=' (and repeated after 'root=').
It should ignore every line where there are no servers listed after rw= or ro=.
For every new server even with the same Type, I want to start a new line, if there is more than one server listed they are seperated by a ':' .
I thought that it would be possible to list it with a loop that contains IFS ':' . But im not quite sure how to write it...
can someone help me? thanks in advance
I have tried it with:
awk -v RS="=====" -v OFS="," 'BEGIN {print "vFiler", "Type" } NF{print $1, $2}'
and a while loop I think that might be working:
while IFS=':' read -r host $1-$#;
but I dont know if the loop is correct or where to put it.
Upvotes: 1
Views: 867
Reputation: 16997
Try this script might help you
Input
akshay@Aix:/tmp$ cat file
===== fspCIV0
/vol/vol0 -sec=sys,rw=fspsanp42.net,root=fspsanp42.net,nosuid
===== fcvCIS01
/vol/ARDW -sec=sys,rw
/vol/ARDW -sec=sys,rw
/vol/ARDW -sec=sys,rw,nosuid
/vol/ARDW -sec=sys,rw
/vol/ARDW -sec=sys,rw=none
/vol/lonulixda -sec=sys,rw=fcvsan10.net:fcvsan11.net,root=fcvsan10.net:fcvsan11.net
Script
akshay@Aix:/tmp$ cat parse_log.awk
BEGIN{
print "vFiler", "Type", "host"
}
/=====/{
vFiler=$2
next
}
match($0,/root=[^,]*/){
n=split(substr($0,RSTART+5,RLENGTH-5),N,/:/)
for(i=1; i<=n; i++)print vFiler,$1,N[i];
}
How to execute ?
akshay@Aix:/tmp$ awk -vOFS="," -f parse_log.awk file
Output
vFiler,Type,host
fspCIV0,/vol/vol0,fspsanp42.net
fcvCIS01,/vol/lonulixda,fcvsan10.net
fcvCIS01,/vol/lonulixda,fcvsan11.net
Upvotes: 1
Reputation: 26667
simple version would be
awk -F[,\ =] '/^=====/{filler=$7} /r[wo]=[^.]*.net/{split($5, a, ":"); for (i in a) print filler,$1,a[i]}'
which would give output as
fspCIV0 /vol/vol0 fspsanp42.net
fcvCIS01 /vol/lonulixda fcvsan10.net
fcvCIS01 /vol/lonulixda fcvsan11.net
Upvotes: 0