0

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

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by JeoSaurus
0

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

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

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

mv location1 location2
e.g
mv /tmp/temp.txt /tmp/finished.txt
0

oooic... I get what ur means already...
Done liao..
haha..!!
thank you chris5126

0

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:

## the quotes are important!
RESULT="$(command --switches)"
echo "$RESULT" > /tmp/finished.txt

Hope that helps!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.