943,772 Members | Top Members by Rank

Ad:
Nov 6th, 2008
0

How to generate a temp file until finish selected then replace to another file.

Expand Post »
Hi All,

I am facing a problem. I need to do a script which to generate the temp.txt file first when select from database, until the data finish store into temp file then -> MV temp.txt to finish.txt.

Any idea? or any sample script for me to refer? I am shell script beginner. Thank you
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ckcy2005 is offline Offline
2 posts
since Nov 2008
Nov 6th, 2008
0

Re: How to generate a temp file until finish selected then replace to another file.

Ot create a file and pipe something into it whatever you like you can use the redirect to a file

Shell Scripting Syntax (Toggle Plain Text)
  1. echo "hello" > /tmp/temp.txt
This will open a new file or overwrite an existing file in the same location and then put the text hello into /tmp/temp.txt. If you want to add addtional lines use the following command
Shell Scripting Syntax (Toggle Plain Text)
  1. echo "hello chris" >> /tmp/temp.txt
You file will then contain hello followed by hello chris to move this file from one location to the other use the following code
Shell Scripting Syntax (Toggle Plain Text)
  1. mv location1 location2
  2. e.g
  3. mv /tmp/temp.txt /tmp/finished.txt
Reputation Points: 38
Solved Threads: 15
Posting Pro in Training
chris5126 is offline Offline
412 posts
since Feb 2006
Nov 7th, 2008
0

Re: How to generate a temp file until finish selected then replace to another file.

oooic... I get what ur means already...
Done liao..
haha..!!
thank you chris5126
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ckcy2005 is offline Offline
2 posts
since Nov 2008
Nov 7th, 2008
0

Re: How to generate a temp file until finish selected then replace to another file.

Do you use the temporary file for anything in the meantime? I'm biased against temporary files when they can be avoided, personally... Why not stuff it all into a variable and then stuff it into a file when it's done, or just write directly to the destination file? Here's an example of using a variable:

Shell Scripting Syntax (Toggle Plain Text)
  1. ## the quotes are important!
  2. RESULT="$(command --switches)"
  3. echo "$RESULT" > /tmp/finished.txt

Hope that helps!
Reputation Points: 46
Solved Threads: 28
Junior Poster
Gromit is offline Offline
183 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: How to check my conditions....!!!
Next Thread in Shell Scripting Forum Timeline: My own shell-wannabe





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC