use `date +%a' '%b' '%d` once is enough. don't put it together with grep. you don't want to call date everytime sed pass a line to grep.
Code:
datepattern=`date +%a' '%b' '%d`
sed .... | grep $datepattern
with GNU awk
Code:
awk 'BEGIN{
datepattern = "^"strftime("%a %b %d",systime())
}
/category/{
if (x ~ datepattern){
scrape(x)
}
getline l
if (l ~ datepattern){
# do something with below line
}
}
{
x=$0
}
function scrape(s){
o=s
gsub(/.*<location>/,"",o)
gsub(/<\/location>.*/,"",o)
print "location: ",o
gsub(/.*<department>/,"",x)
gsub(/<\/department>.*/,"",x)
print "dept: "x
}' file
|