Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my first program .....help me please

Status
Not open for further replies.

zoufri75

Technical User
Mar 17, 2002
25
FR
my fic is like that :

r04 VIDOPCLI 04 * 0120
r04 VIDOPCVM 04 * 028
aST VIDSTATS ST * 050
r16 HTEBAC16 16 * 0250 30788 16
aHT HTBACS HT * 0120 T 0203

I want to change the last field of the last line which contains /HTBACS/ to the current date `date +%m%y`


i'm a beginner..i have try something like that..but it does'nt work....

####
##
#
datedumois=`date +%m%y`
date_fic=` grep HTBACS fic_htbacs | awk '{print $7}'`
if [[ $date_fic = $datedumois ]]
then
break
else
awk '/HTBACS/ {datedumois='`date +%m%y`' ;
$NF = datedumois ;
print $1"\t\t\t\t\t"$2"\t"$3"\t"$4"\t\t\t"$5,$6,$7 }' fic_htbacs >> fic_htbacs

fi

if u could help me ...
thanks for all

Zak from Paris



 
Do you mean this?

awk -vdt=`date +%m%y` '{
if( index($0, "HTBACS") != 0) $(NF) = dt
printf( "%s %-8s %-12s %-10s %-10s %-10s %-10s\n",
$1, $2, $3, $4, $5, $6, $7 )
}' fic_htbacs > fic_htbacs.new

Regards Gregor Gregor.Weertman@mailcity.com
 
no i want that the new line generate by the awk command replace the last line of my fic "fic_htbacs" which contains /HTBACS/.

Regards zak from Paris.
 
Maybe this is what you mean

#!/usr/bin/sh
ln=`awk '/HTBACS/ {ln = NR } END{ print ln}' fic_htbacs`
awk -vln=$ln -vdt=`date +%m%y` '{
if( index($0, "HTBACS") != 0 && ln == NR) $(NF) = dt
printf( "%s %-8s %-12s %-10s %-10s %-10s %-10s\n",
$1, $2, $3, $4, $5, $6, $7 )
}' fic_htbacs > fic_htbacs.new

Regards Gregor Gregor.Weertman@mailcity.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top