The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
renaming xls file systemsb UNIX for Dummies Questions & Answers 2 10-19-2007 08:50 AM
Help in renaming file !!! kumarsaravana_s UNIX for Dummies Questions & Answers 5 05-02-2007 01:45 PM
Mass file renaming Indalecio UNIX for Dummies Questions & Answers 5 12-30-2006 05:16 AM
Renaming a file name dbrundrett Shell Programming and Scripting 2 01-06-2004 10:36 AM
Renaming a file to the same name lachino8 UNIX for Dummies Questions & Answers 3 07-31-2002 09:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-25-2005
ajubi ajubi is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 3
Question renaming the file with the timestamp

Hi, I am new to Shell programming, can any one help me with a shell program which can find a file and the rename it with a current datestamp and move it to a different directory. Advices/suggestions are welcome and Thanks in advance.
  #2 (permalink)  
Old 11-25-2005
bourne bourne is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 25
not sure..but try this ...

cp file tempfile
mv tempfile file
  #3 (permalink)  
Old 12-05-2005
ajubi ajubi is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 3
I am trying something like this..

cd /in # Go to in the folder.
if [ -f "$File.xml"]; then # Check for the file if it exists
mv projects.xml ../program # move the file to program directory
fi
cd ../program # cd to the program directory
run command # run the command.

It throws me a error something like this, Please advise..

file.sh: [: missing `]'

???
  #4 (permalink)  
Old 12-05-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by ajubi
I am trying something like this..

cd /in # Go to in the folder.
if [ -f "$File.xml"]; then # Check for the file if it exists
mv projects.xml ../program # move the file to program directory
fi
cd ../program # cd to the program directory
run command # run the command.

It throws me a error something like this, Please advise..

file.sh: [: missing `]'

???

Code:
if [ -f  "$File.xml"]; then

should be

Code:
if [ -f  "$File.xml" ] ; then

Note the whitespace after ..xml" and before ]


Code:
mv projects.xml ../program

should preferrably be

Code:
mv "$File.xml" ../program

  #5 (permalink)  
Old 12-05-2005
ajubi ajubi is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 3
Hey Thanks but while i use the below code, there isnt any error, but the file is not getting moved.. Is there any reason why? the file name lying unde is projects.xml, which i am trying to move to xog folder...

cd in
if [ -f "$projects.xml" ] ; then
mv "$projects.xml" ../xog
fi
  #6 (permalink)  
Old 12-05-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by ajubi
Hey Thanks but while i use the below code, there isnt any error, but the file is not getting moved.. Is there any reason why? the file name lying unde is projects.xml, which i am trying to move to xog folder...

cd in
if [ -f "$projects.xml" ] ; then
mv "$projects.xml" ../xog
fi
Ideally it should move to the new location.

See what happens in the debugging mode

Enable the debug option. Put a

Code:
set -x

before the "if [ -f.." and


Code:
set +x

after the "fi"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0