Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

csplit

Status
Not open for further replies.

kgiber

MIS
Jun 12, 2001
8
US
empty file
I need to empty the contents of a file save it to a new file without removing the file. I have thought of using csplit any ideas ?
 
This may not be the best way, but could you just do something like this?:

cat file1 > file2
cp /dev/null file1

The first command should write out all of the contents of file1 (assuming it's not a binary) to file2. The second command will just "zero" out file1 without removing it.

HTH,
Jason
 
Why not just using the normal "cp" with the -p flag (to get the same permission bits and owner settings for the copy) and afterwards just rub out file1's contents?

Like this:
cp -p file1 file2
>file1

More elegant, isn't it?
 
I am having problems with the following commands which run in a script. It looses it after the first log. Any suggestions?

Thanks Kat
f=/home/rm35430/kat/ods00000_sql.log
cp -p $f $f.`date +%y%m%d%H%M`
cat >$f<<!
g=/home/rm35430/kat/ods00100_sql.log
cp -p $g $g.`date +%y%m%d%H%M`
cat >$g<<!
h=/home/rm35430/kat/ods00200_sql.log
cp -p $h $h.`date +%y%m%d%H%M`
cat >$h<<!
mv ods00000_sql.log.* old*
mv ods00100_sql.log.* old*
mv ods00200_sql.log.* old*

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top