Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

unix and linux commands - unix shell scripting

sed delete lines containing text1 or text2

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-11-2008   -   Original Discussion by unclecameron
unclecameron's Unix or Linux Image
unclecameron unclecameron is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 18 November 2015, 1:00 PM EST
Posts: 116
Thanks: 14
Thanked 2 Times in 2 Posts
sed delete lines containing text1 or text2

I'm trying to find all occurrences of lines with "sometext" or "someothertext" in them in a log file and remove them, then write the output to the same file, so far I have

sed '/sometext/d' logfile

which gives me the lines I'm looking for, but how would I do:

sed '/sometext/d' or '/someothertext/d' logfile > logfile

what am I missing?
Sponsored Links
    #2  
Old Unix and Linux 11-11-2008   -   Original Discussion by unclecameron
chatwizrd's Unix or Linux Image
chatwizrd chatwizrd is offline
Banned
 
Join Date: Nov 2008
Last Activity: 2 July 2014, 11:24 AM EDT
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
What you are doing should work fine. You just have to name the new file something else not the same file.

Like:



Code:
sed -e '/sometext/d' -e '/someothertext/d' logfile > logfilenew
mv logfilenew logfile

Sponsored Links
    #3  
Old Unix and Linux 11-12-2008   -   Original Discussion by unclecameron
unclecameron's Unix or Linux Image
unclecameron unclecameron is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 18 November 2015, 1:00 PM EST
Posts: 116
Thanks: 14
Thanked 2 Times in 2 Posts
THANKS! Linux I knew I was getting close, but you've definitely helped.
Sponsored Links
Closed


Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sed/awk to delete single lines that aren't touching other lines slimjbe Shell Programming and Scripting 6 12-21-2011 01:37 PM
search and replace, when found, delete multiple lines, add new set of lines? DeuceLee Shell Programming and Scripting 3 11-23-2011 04:39 PM
In a huge file, Delete duplicate lines leaving unique lines krishnix UNIX for Advanced & Expert Users 16 08-04-2011 05:47 AM
How get only required lines & delete the rest of the lines in file reva UNIX for Dummies Questions & Answers 7 06-01-2010 03:58 AM
How to delete lines in a file that have duplicates or derive the lines that aper once necroman08 Shell Programming and Scripting 3 07-17-2009 06:07 AM



All times are GMT -4. The time now is 07:12 AM.