my fic is like that :
$more site
r04 VIDOPCLI 04 * 0120
r04 VIDOPCVM 04 * 028
aST VIDSTATS ST * 050
r16 HTEBAC16 16 * 0250 30788 16
aHT HTBACS HT * 0120 T 0302
I want to change the last field of the last line which contains /HTBACS/ to the current date `date +%m%y`
in our case now : "0402" and not modify the strcuture of the file
i have try something like that..but it does'nt respect the structure of the file
####
##
#
datedumois=`date +%m%y`
date_fic=` grep HTBACS site | awk '{print $7}'`
if [[ $date_fic = $datedumois ]]
then
echo "le fichier n'as pas besoin d etre mis a jour" > site.log
break
else
awk '$0 !~ /HTBACS/ ' site > site.$$
awk '/HTBACS/ {datedumois="'`date +%m%y`'" ; $NF = datedumois ;
print $1"\t\t\t\t\t"$2" "$3"\t "$4"\t\t\t "$5,$6,$7 }
' site >> site.$$
[ $? -eq 0 ] && mv site.$$ site
fi
if u could help me ...
thanks for all
Zak from Paris
i have also try with sed...sed dont modify the structure of my file but i don't know how to use my variable "datedumois"
$more site
r04 VIDOPCLI 04 * 0120
r04 VIDOPCVM 04 * 028
aST VIDSTATS ST * 050
r16 HTEBAC16 16 * 0250 30788 16
aHT HTBACS HT * 0120 T 0302
I want to change the last field of the last line which contains /HTBACS/ to the current date `date +%m%y`
in our case now : "0402" and not modify the strcuture of the file
i have try something like that..but it does'nt respect the structure of the file
####
##
#
datedumois=`date +%m%y`
date_fic=` grep HTBACS site | awk '{print $7}'`
if [[ $date_fic = $datedumois ]]
then
echo "le fichier n'as pas besoin d etre mis a jour" > site.log
break
else
awk '$0 !~ /HTBACS/ ' site > site.$$
awk '/HTBACS/ {datedumois="'`date +%m%y`'" ; $NF = datedumois ;
print $1"\t\t\t\t\t"$2" "$3"\t "$4"\t\t\t "$5,$6,$7 }
' site >> site.$$
[ $? -eq 0 ] && mv site.$$ site
fi
if u could help me ...
thanks for all
Zak from Paris
i have also try with sed...sed dont modify the structure of my file but i don't know how to use my variable "datedumois"