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

reading a parameter file to modify one of the parameters 1

Status
Not open for further replies.

confuseddddd

Programmer
May 22, 2003
53
US
Have a parameter file that contains many parameters but stuck in the middle of all the parameters are the ones I need to modify. I want to be able to do this processing in a script instead of coding a program. Can anyone give me some suggestions on trying to read the parameter file and modify the parameters???

Parameter File is:
REPORT_PRINTER >../EXE/msprint.ex
SYSTEM_PRINTER >../EXE/msprint.ex
EDIT_PROGRAM ../EXE/pico
ARCHIVE_PATH ../ARCHIVE/
BIL_BAL Y
WORK_PATH ../WORK/
BILL_TRANSACTION_LOG Y
START_DATE_YMD 20030501
END_DATE_YMD 20030531
SENDER_ID 363839542
RECEIVER_ID 610600439
TEST_IND P

I need to change the start and end dates each month. I started to do the following:
date '+%Y%m%d' > $datefile
grep -y START_DATE parameter.ini > start
grep -y END_DATE parameter.ini > end
but then realized I don't need to separate the start and end dates just to find the start_date and end_date parameters and change the dates accordingly.

Sorry am new to unix scripting and just need some guidance.
Thanks in advance for your help.
 
Try sed :
DATE=`date '+%Y%m%d'`
sed 's/YMD 20030501/YMD $DATE/' paramfile > tmpfile
mv tmpfile paramfile


Dickie Bird (:)-)))
 
Tried the following as noted above:
DATE=`date '+%Y%m%d'`
sed 's/YMD 20030501/YMD $DATE/' paramfile > tmpfile
mv tmpfile paramfile

and received for START_DATE_YMD $DATE
not the current date in year month day format

Any other suggestions????
 
use DOUBLE-quotes instead:

sed "s/YMD 20030501/YMD $DATE/" paramfile > tmpfile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Tried using double quotes and date did not change to $NEWDATE but it also did not change the date.

Input is
. other parameters
.
START_DATE_YMD 20030501
END_DATE_YMD 20030531
.
. other parameters

Script is
NEWDATE=`date '+%Y%m%d'`
sed &quot;s/YMD 20030501/YMD $NEWDATE/&quot; transfile.ini > tmpfile
sed &quot;s/YMD END_DATE/YMD $NEWDATE/&quot; transfile.ini > tmpfile
mv tmpfile paramfile


I was trying to not have to 'hard-code' the previous month's date but to use the START_DATE and END_DATE instead
to modify the real date.
Script will be run on the last day of the month, so end date can just be that date in ymd format but I need to modify the start date to be the first day of the month.

Any other suggestions????
 
sed -e &quot;%s/YMD 20030501/YMD ${NEWDATE}/g&quot; -e &quot;%s/YMD END_DATE/YMD ${NEWDATE}/g&quot; transfile.ini > tmpfile


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Okay in the sed statement it did not initial work. I removed the % from the %s and the sed statement worked....

Thanks for your help!!!
 
I decided to write a nawk script instead and got the part of the results I expected but I have one issue....

the replaced line contains both the new date and old date:
START_DATE_YMD 20030601 20030501
END_DATE_YMD 20030613 20030531

I just want the new date, have any ideas on how I can remove the extra date???
Here is the script...
nawk 'BEGIN{
PRE='`date -u +%Y%m%d`'
}

{
if ( substr($1,1) == &quot;START_DATE_YMD&quot; ) {
STARTDATE=substr($2,1)
STARTDAY=substr(STARTDATE,7,2)
BEGDATE=substr(PRE,1,6)
WORKDATE=cat BEGDATE STARTDAY
$1=cat &quot;START_DATE_YMD &quot; WORKDATE
}

if ( substr($1,1) == &quot;END_DATE_YMD&quot; ) {
ENDDATE=substr($2,1)
ENDDATE=PRE
$1=cat &quot;END_DATE_YMD &quot; ENDDATE
}

print $0 >> &quot;transfile.in2&quot;
}

END {

}' $INFILE
 
Code:
nawk 'BEGIN{PRE=&quot;'`date -u +%Y%m%d`'&quot;}
/START_DATE_YMD/{$2=substr(PRE,16)&quot;01&quot;}
/END_DATE_YMD/{$2=PRE}
{print}
' <$INFILE >transfile.in2

Hope This Help
PH.
 
Thanks for the suggestion and the end date was changed properly but the start date wasn't....

Here is the output.
START_DATE_YMD 01
END_DATE_YMD 20030613

Here is the updated script.
## FILE DECLARES
INFILE=&quot;transfile.ini&quot;
OUTFILE=&quot;&quot;

nawk 'BEGIN{PRE=&quot;'`date -u +%Y%m%d`'&quot;}
/START_DATE_YMD/{$2=substr(PRE,16)&quot;01&quot;}
/END_DATE_YMD/{$2=PRE}
{print}
' <$INFILE >transfile.in2
 
Sorry for the typo:
Code:
/START_DATE_YMD/{$2=substr(PRE,1,6)&quot;01&quot;}

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top