mercredi 7 octobre 2015

in awk facing issues while using variable as search pattern while searching in a file

date;
tocompdate=$(date --date="-90 days ago" +%d%m%Y)
echo $tocompdate;

awk -v pattern="$testdate" '{print "Some matter "nr[NR--]" matter "$testdate""};' tocompare.txt >> mail2sent.txt`

Here I am taking current date and adding 90 days to it and storing it in tocompdate. And comparing tocompdate with a file, where same date is present in a line and some other matter in other line before that line.

while search pattern is matched I need some text to be printed and "the line before matched line" to be printed and again matched line after few words.

For example:

File has below content

a1
28112019
b2
04032018
c3
04032018
d4
27072015
e5
27072015
f6
06012030

If I am comparing with 27072015, I want output as below

The d4 is on 27072015
The e5 is on 27072015

Aucun commentaire:

Enregistrer un commentaire