sed with Timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed with Timestamp
# 1  
Old 01-30-2015
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

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

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

Any idea ?

Thanks in advance

Last edited by Don Cragun; 01-30-2015 at 01:16 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 01-30-2015
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.
https://www.unix.com/misc.php?do=cfrules

As for your requirement following may help you in same.
Code:
echo $A
abc.xml
echo $A  | awk -vDATE=`date +%Y` '{sub(/\./,"&"DATE".",$0);print}'

Output will be as follows.
Code:
abc.2015.xml

Thanks,
R. Singh
# 3  
Old 01-30-2015
Quote:
Originally Posted by mohanpadamata
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

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

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

Any idea ?

Thanks in advance
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?
# 4  
Old 01-30-2015
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.
# 5  
Old 01-30-2015
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

3. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

4. Shell Programming and Scripting

sed finds nothing but it changes file's timestamp

I must go through some files to change a certain string within text files to another string. I use openSUSE and folders are mounted by cifs. Text to be replaced (only in .m extension) is U:\FOLDER and new string is N: That works fine with spaces in directory names etc., but this process ... (5 Replies)
Discussion started by: Pappa41
5 Replies

5. Shell Programming and Scripting

Identifying files with a timestamp greater than a given timestamp

I need to be able to identify files with file timestamps greater than a given timestamp. I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies

6. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

7. Shell Programming and Scripting

Fix timestamp with Sed or Awk

Hi I am dealing with the following string: Date: Thur, 13 March 2011 01:01:10 +0000 I asked for help in another topic that converted a similar string: Date: Thur, 13 March 2011 9:50 AM To a 24 hr standard. The problem is that it comes out as: Date: Thur, 13 March 2011 9:50:00 +0000... (4 Replies)
Discussion started by: duonut
4 Replies

8. Shell Programming and Scripting

Separate date timestamp use awk or sed command ?

Hi, I have logfile like this : Actually the format is date format : yyyymmddHHMMSS and i want the log become this format yyyy-mm-dd HH:MM:SS for example 2009-07-19 11:46:52 Can somebody help me ? Thanks in advance (3 Replies)
Discussion started by: justbow
3 Replies

9. Linux

SED/AWK Script to clear log file using timestamp?

I have a log file on our system which fills up with lines that have been timestamped, as follows.... 03/03/2008 10:56:06:815] (ERROR) balance: continuing session to genapp02 : 18500 03/03/2008 10:56:06:820] (ERROR) balance: continuing session to genapp02 : 18500 03/03/2008 10:56:07:003]... (2 Replies)
Discussion started by: davesimm
2 Replies

10. UNIX for Advanced & Expert Users

Deleting timestamp using sed command

Hi, I'm trying to compare Actual.html with a baseline.html However, everytime it fails b'coz of the timestamp differences between the two. So, thought of stripping off the timestamp from both the *html files before comparing using below sed command over Solaris Unix platform:... (3 Replies)
Discussion started by: elearn.latha
3 Replies
Login or Register to Ask a Question