sed with Timestamp

Hi,

I would like to replace a "." with timestamp.
Constraint : I am making use of an existing shell script(called by a C program ) which reads the sed command from a properties file.I cant use/pass variables

Line in C program - $(echo ${filename} | sed "$TRANSFORM"
$TRANSFORM is populated using the line in properties file as below

Name-Transform: s/.xml$/$(date +%Y).xml/

input : abc.xml
Output : abc.$(date +%Y).xml
Expected output : abc2015.xml

Any idea ?

Thanks in advance

Hello mohanpadamata,

As per forum rules, please use code tags for commands/inputs/codes used in your posts, following is the URL for rules of forum.

As for your requirement following may help you in same.

echo $A
abc.xml
echo $A  | awk -vDATE=`date +%Y` '{sub(/\./,"&"DATE".",$0);print}'

Output will be as follows.

abc.2015.xml

Thanks,
R. Singh

There are several things wrong here:

  1. You say you can't use/pass variables and then you show us code that passes the shell variables filename , TRANSFORM , and, presumably, variables that will correspond to the input , Output , and Expected output fields in your configuration file.
  2. If you have this line: $(echo ${filename} | sed "$TRANSFORM" in your C program, your C program will not compile. Shell command substitutions, pipelines, and variable expansions are not valid in a C program. Even if the calling program is a shell script instead of a C program, the command substitution is incomplete.
  3. There are no quotes in your configuration file. There is no way for a C program or a shell script to delimit the value that is supposed to be assigned to the shell variable TRANSFORM .
  4. The Output format in your configuration file contains two decimal points that appear to be literal characters. The Expected output contains one decimal point. How can these two possibly produce the desired results?

So what is really going on here?

Is this a homework assignment?

Sorry Don. A bit detailed explanation,

Code calls:
Shell script A calls a C program
C program calls Shell script B

Shell script B & C-program are fixed. I can't change them. Shell script B gets the sed string from a properties file .

Properties file contents -> Name-Transform: s/.xml$/$(date +%Y).xml/

Shell script B:
-> gets and stores the sed string in $TRANSFORM.
-> Calls the command - $(echo ${filename} | sed "$TRANSFORM" , for substitution.

Sorry for misleading. Below are the testing results.

input filename : abc.xml
I am getting Output as : abc.$(date +%Y).xml
I am Expecting output : abc2015.xml

What is required for me? I need the sed string which i can use in properties file.

Please advise . Let me know if you need more details.

Whoever created this "C-program calling B-script reading properties file" must have documented their ideas on its usage and structures. What's in this documentation? Did this ever work?