The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cannot store integer value bennichan Shell Programming and Scripting 5 04-10-2008 11:20 AM
Grep results to store in a shell variable jojan Shell Programming and Scripting 3 07-26-2007 09:44 AM
how can i store it ? shamal High Level Programming 2 12-08-2001 01:19 AM
How to store username dinplant Shell Programming and Scripting 3 11-13-2001 05:34 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2005
Registered User
 

Join Date: Oct 2004
Posts: 221
Stumble this Post!
grep and store

When i grep a file and store it in a file it is storing as a zero byte file any way to avoid that.....
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-02-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,325
Stumble this Post!
Post your command. There is no way to give an accurate answer without that. Here is a thought though. Are you doing something like:
Code:
grep "something" arunkumar.txt > arunkumar.txt
This will truncate the file first and then run the grep on that file; which will obviously output a zero byte file.
Reply With Quote
  #3 (permalink)  
Old 01-26-2006
Registered User
 

Join Date: Oct 2004
Posts: 221
Stumble this Post!
Thank you but i want to do grep a same file and save in that file is that possible ?? please give some idea
Reply With Quote
  #4 (permalink)  
Old 01-26-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
grep pattern filename >> filename

this would append the pattern search into the filename,

is that you want?
Reply With Quote
  #5 (permalink)  
Old 01-26-2006
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,513
Stumble this Post!
Quote:
Originally Posted by arunkumar_mca
Thank you but i want to do grep a same file and save in that file is that possible ?? please give some idea
Not with grep. However you could do it with sed if you are on a gnu system.
Reply With Quote
  #6 (permalink)  
Old 01-26-2006
Registered User
 

Join Date: Jan 2002
Location: dusseldorf,germany
Posts: 10
Stumble this Post!
try this command

grep "expression" filename | & tee log

This work for all command , one output will redirected to standard output which is screen and another in the file name log.

rajesh
Reply With Quote
  #7 (permalink)  
Old 01-27-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
Stumble this Post!
Two solutions ...

With sed (2 steps):
Code:
sed -n '/expression/p' filename > tempfile
mv tempfile filename
With perl (1 step) :
Code:
perl -n -i -e 'print if /expression/' filename

Jean-Pierre.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:09 AM.


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

Content Relevant URLs by vBSEO 3.2.0