The UNIX and Linux Forums  

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
Korn shell awk use for updating two files alrinno UNIX for Dummies Questions & Answers 4 07-08-2008 03:07 PM
Lookup between 2 files ( korn shell ) pavan_test UNIX for Dummies Questions & Answers 17 01-31-2006 01:07 PM
korn shell + sftp + list files alienET Shell Programming and Scripting 1 03-24-2005 08:12 AM
how to delete empty files in a shell script rpnuge UNIX for Advanced & Expert Users 1 07-11-2002 01:56 PM
Re-initializing startup files without rebooting DrScar UNIX for Dummies Questions & Answers 3 08-20-2001 07:14 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-11-2008
Registered User
 

Join Date: Jun 2008
Posts: 18
Initializing files to empty in korn shell

hello,

i want to know how to initialize a file to an empty one in korn shell scripting? i'm using a file name and building it during a while loop using >>. The problem occurs when the file is not empty before reaching the while loop. therefore, i want to initialize it before the loop to get rid of any prior data.. how can i do that with korn shell scripting?

thanks
Reply With Quote
Forum Sponsor
  #2  
Old 08-11-2008
Ikon's Avatar
Registered User
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 407
This will overwrite OR create the file

Code:
echo "" > /path/to/filename
Reply With Quote
  #3  
Old 08-11-2008
Registered User
 

Join Date: Jun 2008
Posts: 18
thanks Ikon, but this creates an empty line at the beginning of the file. how can i achieve the same result withouth the beginning empty line?
Reply With Quote
  #4  
Old 08-11-2008
Ikon's Avatar
Registered User
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 407
Code:
cat /dev/null > /path/to/filename
Reply With Quote
  #5  
Old 08-11-2008
Registered User
 

Join Date: Jun 2008
Posts: 18
thank you soooo much!
Reply With Quote
  #6  
Old 08-12-2008
broli's Avatar
Registered User
 

Join Date: Dec 2007
Location: Argentina
Posts: 198
or a more "elegant" way

if [ -e /path/to/file ]
rm /path/to/file
fi

altho that is an uncesesary if, you can simple try to rm it and disble output

rm /path/to/file > /dev/null 2>&1
Reply With Quote
  #7  
Old 08-12-2008
ynilesh's Avatar
Registered User
 

Join Date: Oct 2007
Location: Bangalore, India.
Posts: 174
Adding more shell commands matters while running shell script as it invoke subshell.
IMO echoing is good option. as echo is a builtin command.

- nilesh
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0