Hi all,
I have a piece of code which cork perfect. It copy the no of lines from some files (*.log) into finalLog file.
It read the lines after the line have text "ntot".
Here it is :
#!/bin/bash
awk '/ntot/{p=lines;next}
p>0{
split($0,arr,"=")
if(!h[arr[1]"HDR"])h[arr[1]"HDR"]=arr[1]
a[arr[1]]=a[arr[1]]" "$NF
if(j<lines) b[++j]=arr[1]
sum[arr[1]]+=$NF
p--
}
END{
for(i=1;i<=j;i++)
print h[b"HDR"]"="a[b]" "sum
[b]}' lines=1 *.log > finallOG
I modified the script to make it more flexible and so could provide the information of
1.) lines
2.) TEXT
3.) finalLOg file
through terminal. but it is not working. Can anybody suggest what wrong in the new script. Find the new script here:
#!/bin/bash
TEXT=$1
LINES=$2
FINAL=$3
awk '/$TEXT/{p=$LINES;next}
p>0{
echo 'working'
split($0,arr,"=")
if(!h[arr[1]"HDR"])h[arr[1]"HDR"]=arr[1]
a[arr[1]]=a[arr[1]]" "$NF
if(j<lines) b[++j]=arr[1]
sum[arr[1]]+=$NF
p--
}
END{
for(i=1;i<=j;i++)
print h[b"HDR"]"="a[b]" "sum
[b]}' *.log > $FINAL
thanks in advance
pooja..