The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed: find match and delete the line above cstovall Shell Programming and Scripting 3 07-02-2008 07:31 PM
how to delete text from line starting pattern1 up to line before pattern2? repudi8or Shell Programming and Scripting 5 04-15-2008 06:25 PM
Find a word and delete the line gsusarla UNIX for Dummies Questions & Answers 1 04-02-2008 11:45 AM
how to delete line with matching text and line immediately after orahi001 UNIX for Dummies Questions & Answers 6 01-14-2008 09:34 PM
delete a line based on first character of the line borncrazy UNIX for Dummies Questions & Answers 2 12-06-2005 12:27 PM

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

Join Date: Apr 2008
Posts: 10
Find and delete the line

Hi I have a text file like this name today.txt

the request has been accepted
the scan is successful at following time
there are no invalid packages
5169378 : map : Permission Denied
the request has been accepted

Now what i want do is

I want to search the today.txt file and

if i find "permission denied" then I have to delete the whole line.
so that the text looks like this,

the request has been accepted
the scan is successful at following time
there are no invalid packages
the request has been accepted


Any help is appreciated,

gns.
Reply With Quote
Forum Sponsor
  #2  
Old 04-02-2008
Registered User
 

Join Date: Mar 2008
Location: Toronto, Canada
Posts: 66
Try:

Code:
grep -v "Permission Denied" today.txt
Reply With Quote
  #3  
Old 04-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 10
Not working

Hi

if I do

grep -v "Permission denied" today.txt
It is printing the text without the line on the screen

but it si not deleting the line in the file.

So how can I do that, like delete the line from the file itself as i am mailing the file after i do this operation.

Regards,

gns

PS: Sorry for multiple posting
Reply With Quote
  #4  
Old 04-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 10
If i do this

grep -v "Permssion Denied" todat.tx >today.txt 2>&1

its not working

Please help me,

Gns
Reply With Quote
  #5  
Old 04-02-2008
Registered User
 

Join Date: Jun 2006
Posts: 164
Do a quick search on this forum for simple sed commands. I'm not handy with sed myself, but it will allow you to do exactly what you want -- edit the file in one step.
Reply With Quote
  #6  
Old 04-02-2008
Registered User
 

Join Date: Mar 2008
Location: Toronto, Canada
Posts: 66
Be very careful whenever and wherever you use ">myfile" at the end of any command, the content of "myfile" will be cleared completely.

So, doing:

grep -v "bla bla bla" myfile >myfile

will first emty myfile before executing the grep!!!

Having that in your mind, you have to do the following:
Code:
grep -v "Permission Denied" today.txt >tmp.txt; mv tmp.txt today.txt
Reply With Quote
  #7  
Old 04-07-2008
Registered User
 

Join Date: Nov 2007
Posts: 7
Code:
sed "/Denied/ d" test.txt > tmp.txt && mv tmp.txt test.txt
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:16 AM.


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