Appending timestamp to a file. Why do I need this space ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending timestamp to a file. Why do I need this space ?
# 1  
Old 02-20-2013
Appending timestamp to a file. Why do I need this space ?

Version Info
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
$
$ echo $0
-ksh

I was trying to append date to the file name. The following syntax has worked
Code:
 
$ touch HELLO-`date '+%d-%b-%Y'`.txt
$ ls -alrt HELL*
-rw-r--r-- 1 rlapp  oinstall 0 Feb 20 10:28 HELLO-20-Feb-2013.txt
$

There should be a space after the date keyword. Without the space you'll get the following error
Code:
 
## Testing without the space after date keyword
$
$ touch HELLO2-`date'+%d-%b-%Y'`.txt
-ksh: date+%d-%b-%Y: not found [No such file or directory]

Why do I need this space after the date keyword ?
# 2  
Old 02-20-2013
Without the space you are trying to execute a command named date+%d-%b-%Y instead of executing a command named date with the operand +%d-%b-%Y that tells date the format in which you want the date printed.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 02-20-2013
date is a command like any other command, and therefore needs a space behind it if you provide arguments (in this case '+%d-%b-%Y')
This User Gave Thanks to Subbeh For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

2. Shell Programming and Scripting

Find folders with timestamp and disk space used

Hi, I want write a script that finds a set of folders written between a certain time and then find the disk space used by those folders. Can someone please help. Thanks, Sparcman:( (1 Reply)
Discussion started by: sparcman
1 Replies

3. Shell Programming and Scripting

Appending unix timestamp to every line of a statistical file

I have a statistical file populating every minute as below: 2011-11-11-1108 1955 891 2011-11-11-1109 2270 1049 2011-11-11-1110 1930 904 2011-11-11-1111 2030 931 2011-11-11-1112 1944 900 2011-11-11-1113 1922 875 Instead of having the date and time in the given format (2011-11-11-1113) I... (10 Replies)
Discussion started by: thinktank
10 Replies

4. 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

5. UNIX for Dummies Questions & Answers

Appending timestamp problem

Hi, I am trying to insert a timestamp after all the file names in a folder,after the timestamp is created in the filename the file size is becoming zero bytes. please tell me where I am doing it wrong. I have declared the variable in starting of my script. timestamp=`date... (1 Reply)
Discussion started by: shruthidwh
1 Replies

6. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

7. Shell Programming and Scripting

Blank Space is not appending in each row of CSV File - Shell Script

I am calling SQL script in my UNIX Shell script and trying to create the CSV file and my last column value of each row is 23 blank spaces. In my SQL script,the last column is like below. RPAD(' ',23,' ') -- Padding 23 blank Spaces The CSV file is generated but the sapce(23 spaces) is... (2 Replies)
Discussion started by: praka
2 Replies

8. Shell Programming and Scripting

appending space to variable

Hi I need to write a script where there the user enters 3 input parameter variable number the program should ask the user left or right if it is left , the number specified that many spaces should be added to the value in front of the value and saved in the samee variable itself and if it is... (5 Replies)
Discussion started by: viv1
5 Replies

9. UNIX for Dummies Questions & Answers

appending timestamp to a file

hi freinds, i need to append timestamp to a file name to make it unique... do we have any command in unix to do please help :confused: (2 Replies)
Discussion started by: madhu_aqua14
2 Replies

10. Programming

appending space in binary data in c

Hi ... I am having a string in the buffer .. It is binary data it may contain space . When i try to append a space in using strcpy it is taking the inbetween \n as the end and appending space .. How to append space in the binary data in C ?? please let me know Thanks in advance, Arun. (2 Replies)
Discussion started by: arunkumar_mca
2 Replies
Login or Register to Ask a Question