![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Try:
Code:
grep -v "Permission Denied" today.txt |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
If i do this
grep -v "Permssion Denied" todat.tx >today.txt 2>&1 its not working Please help me, Gns |
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
Code:
sed "/Denied/ d" test.txt > tmp.txt && mv tmp.txt test.txt |
|||
| Google The UNIX and Linux Forums |