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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Substitute ADDDATE in Script

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have a file name cmd_cha that has the following statement in it:

@LABEL BEGIN
@SET LOGFILE=("/home/bham_mta/cmd_program/bh1bsc1_cmd_out")
@LOG(LOGFILE)
@SET SWITCH="BH1BSC1"
@CONNECT (SWITCH)
imlct:spg=0;
mcsap:file=tlogio,io1=all,sdate=ADD_DATE,stime=0800;
end;
@CLOSE
@DISCONNECT
@SET LOGFILE=("/home/bham_mta/cmd_program/bh1bsc2_cmd_out")
@LOG(LOGFILE)
@SET SWITCH="BH1BSC2"
@CONNECT (SWITCH)
imlct:spg=0;
mcsap:file=tlogio,io1=all,sdate=ADD_DATE,stime=0800;
end;
@CLOSE
@DISCONNECT

I want a small script that will scan the file and susbtitute the actual date of the prior day anywhere it finds the words ADD_DATE in the date format like 20020523

I hope this is pretty easy, I am a bit rushed for time.

Thanks as always for the help!

Beaster
 
Hi:

Under Solaris 7 ksh:
#!/bin/ksh

date '+%y%m%d' > date.file
nawk ' BEGIN { getline ddate <&quot;date.file&quot; > 0 }
{
gsub(&quot;ADD_DATE&quot;, ddate)
print $0
} ' input > output
rm date.file


Regards,

Ed
 
Can you tell me what date format that will give me? I am looking for it to be 20020523 format....

Regards,
Beaster
 
Beaster:

As I posted it, the date doesn't use the century. It's this format:
020522

Not all the unix variants have a POSIX compliant date. Hard-coding the century should work:

date '+20%y%m%d' > date.file

Regards,


Ed
 
Would't the following be &quot;clearer&quot;? :)


ddate=$(date '+%y%m%d')

nawk -v ddate=${ddate} '
{
gsub(&quot;ADD_DATE&quot;, ddate)
print $0
} ' input > output
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top