append date to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting append date to file
# 1  
Old 08-13-2008
append date to file

Hi

I need to append date to filename.Wrote script to get the date from table ,take this date filed and append to my i/p file when call the below script.Any help should be appreciated .

Exampel

If call the below script

a4.sh filename

o/p should be

filename.2008-02-29


. $HOME/.profile
bteq_file=./bteq_file.txt
rm $bteq_file
touch $bteq_file
echo "bteq << EOF" >> $bteq_file
echo ".logon r01ftdn/LOAD1_xx,xxxTqwe;" >> $bteq_file
echo "database xx_r5;" >> $bteq_file
echo "" >> $bteq_file
loc_code="XX"
freq_code="WC001"
echo "sel Current_process_date from "DATE_CARD" " where location_code=" '$loc_code' " and load_frequency_code="
'$freq_code' " ";">> $bteq_file

echo ".logoff" >> $bteq_file
echo ".quit" >> $bteq_file
echo ".EOF" >> $bteq_file
sh $bteq_file


/
...
....
database xx_r5;

*** New default database accepted.
*** Total elapsed time was 1 second.


+---------+---------+---------+---------+---------+---------+---------+----

sel Current_process_date from DATE_CARD where location_code= 'xx
' and load_frequency_code= 'WC001' ;

*** Query completed. One row found. One column returned.
*** Total elapsed time was 1 second.

Current_Process_Date
--------------------
2008-02-29

+---------+---------+---------+---------+---------+---------+---------+----
.logoff
*** You are now logged off from the DBC.
+---------+---------+---------+---------+---------+---------+---------+----
.quit
*** Exiting BTEQ...
*** RC (return code) = 0



Thanks,
MR
# 2  
Old 08-13-2008
Try this (untested):

Code:
$HOME/.profile
loc_code="XX"
freq_code="WC001"

bteq << EOF > /tmp/bteq.out.$$
.logon r01ftdn/LOAD1_xx,xxxTqwe;
database xx_r5;
sel Current_process_date from "DATE_CARD" where location_code='$loc_code' and load_frequency_code='$freq_code';
.logoff
.quit
EOF

date=$(awk '/Current_Process_Date/ { getline; getline; print }' /tmp/bteq.out.$$)

rm /tmp/bteq.out.$$

echo filename.$date

# 3  
Old 08-13-2008
Hi
Thanks,Its working


Thanks,
MR
# 4  
Old 08-13-2008
Hi
This script is working fine ,but when call this script with i/p file its creating
more spaces between filename and date.I want to remove the sapaces and return as m1.2008-02-29


ex: a5.sh m1

m1. 2008-02-29


$HOME/.profile
file=$1
loc_code="XX"
freq_code="WC001"

bteq << EOF > /tmp/bteq.out.$$
.logon r01ftdn/LOAD1_xx,xxxTqwe;
database xx_r5;
sel Current_process_date from "DATE_CARD" where location_code='$loc_code' and load_frequency_code='$freq_code';
.logoff
.quit
EOF

date=$(awk '/Current_Process_Date/ { getline; getline; print }' /tmp/bteq.out.$$)

rm /tmp/bteq.out.$$

mv $file $file.$date
/

Thanks,
MR




m1. 2008-02-29
# 5  
Old 08-13-2008
Hi

This below script ,take the date field from table and loading into file ,I want to add the date to i/p filename.The problem is when call this script appendintg the date to filename with more spaces(filename .28-02-2008) but when printing there is no spaces between filename and date .It was really surprising .Any help it should really appreciated.

$HOME/.profile
file=$1
loc_code="XX"
freq_code="WC001"

bteq << EOF > /tmp/bteq.out.$$
.logon r01ftdn/LOAD1_xx,xxxTqwe;
database xx_r5;
sel Current_process_date from "DATE_CARD" where location_code='$loc_code' and load_frequency_code='$freq_code';
.logoff
.quit
EOF
date=$(awk '/Current_Process_Date/ { getline; getline; print }' /tmp/bteq.out.$$)
rm /tmp/bteq.out.$$
echo "$date"
echo $file."$date" |sed -e "s/ //g'---Printing filename.date without any space
sed -e "s/ //g" $file."$date">$file1."$date"
mv $file1."$date" $file."$date"--Renaming filename .date


Thanks,
MR
# 6  
Old 08-14-2008
Just change this line:

Code:
date=$(awk '/Current_Process_Date/ { getline; getline; print $1 }' /tmp/bteq.out.$$)

No need for sed or anything.

The sed that you added wasn't working because it was trying to remove spaces from the contents of the file, not the filename. You could have done it like this, but the above way should hopefully be simpler and tidier:

Code:
newfilename=$(echo $file.$date | sed 's/ //g')
mv $file $newfilename

# 7  
Old 08-14-2008
Hi,

Thanks ,Its working

Thanks,
MR
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append date to sql*plus spool (log) file in shell script

SQL*Plus version : 11.2.0.4 OS : Oracle Linux 6.5 SQL*Plus is a client application to connect to oracle database. The log file for this tool is generated via spool command as shown below. I am trying to append date ( $dateString ) to spool file as shown below. $ cat test2.sh #!/bin/bash... (4 Replies)
Discussion started by: kraljic
4 Replies

2. Shell Programming and Scripting

Append orginal file date to end of file

Trying to process 1000 or so files. Take original date and append to end of file. Like so: tstpls42.bas tstpls42.bas.Sep-11--2011 Been working along these lines: date=`ll tstpls42.bas |cut -c 46-57 |sed -e 's/]/\-/g' | grep -v '^$'` for i in *.bas ; do j=`ll $i /hpdump/b1 | awk... (1 Reply)
Discussion started by: joeadmin
1 Replies

3. Shell Programming and Scripting

Want it to read the file name and then append date stamp at the end of file?

I was thinking something like for i in `find . -name "*.log.Z"`; do mv $i name.log.Z or something like that? (3 Replies)
Discussion started by: xgringo
3 Replies

4. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

5. UNIX for Dummies Questions & Answers

append file name with date

Hi guys, I created a very basic script that moves a specified file to a directory that I have set using the mv command. What I would like to do is append the file name with the date and time. So if I was to use the script to move a file called abc.txt, the script should rename the file... (1 Reply)
Discussion started by: jjc
1 Replies

6. UNIX for Dummies Questions & Answers

How To Append Date to File Name - AIX 5.3

Hello, I am a novice user on an AIX 5.3 system. I am running some scripts via crontab and redirecting the output to a file. For example: /home/cognos/ppdev_refresh.sh > /home/cognos/ppdev_refresh.txt I want to append the system date to the file name so it becomes:... (7 Replies)
Discussion started by: Maurice Frank
7 Replies

7. Solaris

Find a file and xarg mv to append date to file

Hello All, What I would like to do is search for a file and then run a mv command to rename the file to have todays date appended to it. The find when I run it finds eight or so files and I would like to append a date stamp to each file. If possible using one line command would be great. Can... (6 Replies)
Discussion started by: jacktravine
6 Replies

8. Solaris

gzip a file and append creation date stamp to file

I want to gzip a file and append the creation date to the end of the file. How can I accomplish this task. Basically they are log files which need a creation date stamp appended to make sure they do not overwrite other log files. -jack (3 Replies)
Discussion started by: jacktravine
3 Replies

9. Shell Programming and Scripting

Append date to a file from CRON

Hi, I am trying to append date in DAY_Mon_dd_yyyy at the end of a filename from cron. Cron entry looks as below. (script to execute) > test_file_`date +"a_%b_%d_%Y"` File name created after executing the job is test_file_ I am expecting the filename to be something like ... (8 Replies)
Discussion started by: dncs
8 Replies

10. Shell Programming and Scripting

Need a script to Append date to generated .txt file

Hi, Can anyone plz share their experience with - Building shell script to append the file with date in following format- Filename_MMDDYYYY.txt Thanks in advance (2 Replies)
Discussion started by: prince_of_focus
2 Replies
Login or Register to Ask a Question