The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

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 07:50 AM
Help in renaming file !!! kumarsaravana_s UNIX for Dummies Questions & Answers 5 05-02-2007 12:45 PM
renaming part of a file ajaya Shell Programming and Scripting 0 04-11-2006 10:00 PM
renaming the file with the timestamp ajubi Shell Programming and Scripting 6 12-05-2005 06:21 AM
Renaming a file name dbrundrett Shell Programming and Scripting 2 01-06-2004 10:36 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 07-30-2002
lachino8 lachino8 is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 5
Question Renaming a file to the same name

Hi All,

I was wondering if anyone knows how i take in a file, format the file, and then rename the file as the same name as the input file in shell script. Here is an example of what I am doing:

if [[$1=""]]
then
echo "please enter a filename"
else
export infile=$1

I take in a file "$infile"

Then I do my formatting.....

Now I want to rename the formatted file back to $infile. How can I do this? Right now it is renaming the file before any formatting is done...and the formatted $infile is empty. Please help me if possible. Thanks.
  #2 (permalink)  
Old 07-30-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 535
Re: Renaming a file to the same name

Quote:
Originally posted by lachino8
Hi All,
Now I want to rename the formatted file back to $infile. How can I do this? Right now it is renaming the file before any formatting is done...and the formatted $infile is empty. Please help me if possible. Thanks.
I would reformat the file to a temp file and when formatting was done, copy it back to the original filename.
  #3 (permalink)  
Old 07-30-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Depends on your formatting you are doing.....if you're just sorting then you're okay to use the same filename for output - just use the -o flag. If your doing pretty much anything else - which I assume you are...then temp file is the only way.

I'd use mv rather than cp though.....so you don't have left over files.
  #4 (permalink)  
Old 07-31-2002
lachino8 lachino8 is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 5
Thumbs up

Thanks guys...I got it. I was just unsure as to how I name the temp file. I got all kinds of errors, but tweaked it and now it works. Thanks for your input!!..much appreciated!

-brian
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 09:22 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