replacing date with a variable in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing date with a variable in a file
# 1  
Old 12-01-2010
Question replacing date with a variable in a file

Hi,

I've a variable for example..
Code:
ACTIVATION_DATE=2010-11-11

(the date above is a result of a sql query and not hardcoded)

now there is another file (test_2.parm) where there are many variables predefined..
Code:
REG_CODE=111
ACT_DATE=2010-10-10
CAN_DATE=8888-31-12

Now I want to search for "ACT_DATE=" in test_2.parm and replace the date there with the date in "ACTIVATION_DATE".. something like tis..

Code:
REG_CODE=111
ACT_DATE=$ACTIVATION_DATE
CAN_DATE=8888-31-12

I tried with few awk n sed scripts but none worked.. Please help.

Thanks in advance,
RRVARMA

Last edited by Franklin52; 12-01-2010 at 05:33 AM.. Reason: Please use code tags
# 2  
Old 12-01-2010
Code:
ACTIVATION_DATE=2010-11-11

awk -F= -v var="$ACTIVATION_DATE" '/ACT_DATE/{$2=var}1' OFS="=" test_2.parm > newfile

Or:
Code:
ACTIVATION_DATE=2010-11-11

sed 's/\(ACT_DATE=\).*/\1'"$ACTIVATION_DATE"'/' test_2.parm > newfile

This User Gave Thanks to Franklin52 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux Commands needed for replacing variable number of spaces with a single , in a txt file

Hi I want to read a text file and replace various number of spaces between each string in to a single "," or any other character .Please let me know the command to do so. My input file is a txt file which is the output of a SQL table extract so it contains so many spaces between each column of the... (2 Replies)
Discussion started by: Hari Prasanth
2 Replies

2. Shell Programming and Scripting

Replacing Date in the file with Create date and timestamp

Hello, I have files that with a naming convention as shown below. Some of the files have dates in the file name and some of them don't have dates in the file name. imap-hp-import-20150917.txt imap-dell-gec-import-20150901.txt imap-cvs-import-20150915.txt imap-gec-import.txt... (8 Replies)
Discussion started by: Saanvi1
8 Replies

3. Shell Programming and Scripting

How to search file for a date variable?

Hello, I'm trying to write a ksh script which will allow me to to search for yesterday's date within a rtf file. I just need someway to know if the date is in the file, echo results to a text file, and then mail that out. The format of the date is mm/dd/yyyy. I had to make a variable... (2 Replies)
Discussion started by: ronan1219
2 Replies

4. Shell Programming and Scripting

passing variable to another file and replacing

Hi all, I have a script in file1 which gets input from the user say variable "TYPE". This variable is present in the other file2. I want to replace the variable in the file2 with the value given by the user and print the file. How can I achieve this task? file1 code echo "Give... (3 Replies)
Discussion started by: Ananthdoss
3 Replies

5. Shell Programming and Scripting

Replacing / by - in date

Dear Friends, Following is manupulated output of our script. e.g. lkme_lpst 2 Pur_dt 31/12/2011 bl_dt 01/02/2011 rt_dt 02/02/2011 prod_btch 19/1452147-5210 We further want to manupulate it and want to replace / by - i.e. Lkme_lpst 2 Pur_dt 31-12-2011 bl_dt 01-02-2011... (7 Replies)
Discussion started by: anushree.a
7 Replies

6. Homework & Coursework Questions

How do I get at the modification date for a file as a variable for a script?

I realize this is basic and probably obvious, but I'm pulling my hair out. I'm guessing this is just some flag on the file command or somesuch, but I can't find it. Help me get unstuck please? EDIT: I guess what I'm asking is once I've got the ls -l output for a file, what command do I use to... (3 Replies)
Discussion started by: Timespike
3 Replies

7. Shell Programming and Scripting

Renaming a file and replacing the special character in the name with date

HI all, How can i rename some files and replace the special character in the name with todays date ex: Name#file1.txt Name#file2.txt to be renamed as Name.20091119.file1.txt Name.20091119.file2.txt (11 Replies)
Discussion started by: abhinav192
11 Replies

8. Shell Programming and Scripting

searching a date and replacing with another date

I have a text file that i want to search through and pick out any dates that are formatted like MM/DD/YYYY and replace them with a date i want like 10/29/2009. any idea show i would do this?:) Snapshot of my text file: test4>s44syd5172>070>528>ENU>nongnuan>wanrawee>sr2330532>... (7 Replies)
Discussion started by: infiant
7 Replies

9. Shell Programming and Scripting

Need help in sed command ( Replacing a pattern inside a file with a variable value )

Hello, The following sed command is giving error sed: -e expression #1, char 13: unknown option to `s' The sed command is echo "//-----" | sed "s/\/\/---*/$parChk/g" where parChk="//---ee-" How can i print the variable value from sed command ? And is it possible to replace a... (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. Shell Programming and Scripting

Help needed - Replacing all date & time occurrences in a file with a string using Sed

Hi, I am new to using Sed. I have a file containg lines like the following: INFORM----Test.pc:168:10/11/05 12:34:26 > some text goes here.. TRACE-----Test.pc:197:10/11/05 12:34:26 > some text goes here.. My requirement is to replace 10/11/05 12:34:26 with a string <RUNDATE> (including <... (4 Replies)
Discussion started by: Hema_M
4 Replies
Login or Register to Ask a Question