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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell Programming and Scripting nivas Shell Programming and Scripting 20 02-27-2008 06:36 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 21 02-25-2008 06:27 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 2 02-20-2008 02:59 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 14 02-20-2008 02:07 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 3 02-13-2008 08:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-10-2009
praka praka is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 18
Post Removing the entire file contents using unix shell script.

I need to remove the entire file contents in file using the shell script.

Actually the grap -v command will create one more file and it occupy the space also.

I need to remove the entire file contents without creating new file using the shell scripting.

Please help me.

Last edited by praka; 02-10-2009 at 02:58 AM.. Reason: changed the title.
  #2 (permalink)  
Old 02-10-2009
scorpio scorpio is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 41
if u want to nullify the file use
:>filename
  #3 (permalink)  
Old 02-10-2009
praka praka is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 18
Smile

Thanks for your information.
Can you please give complete script.
  #4 (permalink)  
Old 02-10-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,788
Either
Code:
$ :>file
or, a bit more brutal,
Code:
$ rm -f file && touch file
The second one, though, will cause quite some havoc if a process still has a filehandle open on it.
  #5 (permalink)  
Old 02-10-2009
praka praka is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 18
whether this code $ :>file
will remove all contents from file and put into another file?

If yes then i need code to remove all the file contents without creating new file.

The other code is ok. remove the file and touch file.
  #6 (permalink)  
Old 02-10-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,788
':>file' tells the shell to redirect the output of the NOOP command (which is none) to "file", creating it if it doesn't exist, or truncating it if it exists.
Sponsored Links
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 02:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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