removing lines that match a pattern from a file

removing lines that match a pattern from a file

Post by Thomas Da » Sun, 09 Mar 2003 18:23:39



I have a list of patterns in a file and I want to
go through that list a remove lines in a log file that match those patterns
so I;m left with a log file without those patterns

I was going to use grep -v <pattern> logfile

But I'm not sure how to do this with a whole list pf patterns, any
suggestions would be greatly appreciated,

 
 
 

removing lines that match a pattern from a file

Post by Thomas Da » Sun, 09 Mar 2003 18:55:25


Actually I am using grep -v -f <patterns.txt>  to rm the unwanted patterns
is there another way to do this?  how do I rm blank lines from the resulting
file?


Quote:> I have a list of patterns in a file and I want to
> go through that list a remove lines in a log file that match those
patterns
> so I;m left with a log file without those patterns

> I was going to use grep -v <pattern> logfile

> But I'm not sure how to do this with a whole list pf patterns, any
> suggestions would be greatly appreciated,


 
 
 

removing lines that match a pattern from a file

Post by yan » Mon, 10 Mar 2003 00:42:57


i am not sure this answer is what you want:
except using grep, you can also use sed, awk
1.  sed 's/pattern//g' logfile
2.  sed '/^[ \t]*/d' logfile     will delete blank lines
3.  awk '{if ($0 !~ /pattern/){print $0}' logfile
4. awk '/^[ \t]*{print $0}' logfile will delete blank lines

Originally posted by Thomas Dao

> Actually I am using grep -v -f   to rm the unwanted patterns
> is there another way to do this?  how do I rm blank lines from the
> resulting
> file?



> racle.com[/url]...
> > I have a list of patterns in a file and I want to
> > go through that list a remove lines in a log file that match
>     those
> patterns
> > so I;m left with a log file without those patterns
> > I was going to use grep -v  logfile
> > But I'm not sure how to do this with a whole list pf patterns,
>     any
> suggestions would be greatly appreciated,

--
Posted via http://dbforums.com
 
 
 

1. Matching a pattern in a file and inserting variable string above the line matched?

Hello all,  here is a snipet of code for a problem i'm having.  I've
tried to use sed for this, but i cannot get the variable substitution
worked out.

print "Please enter each username(s) you wish to add: "      
read NAMES
for USER in $NAMES ; do
  if egrep "^$USER" /etc/passwd > /dev/null ; then
       ### insert sed, awk, or perl code here
  fi
done

### The layout of the file is:
root ADMIN=ALL JBP=ALL
* ADMIN=JBP JBP=ENDUSER+BU+ARC

For each $USER, I need to add the following string ABOVE
the "* ADMIN=JBP" line in the file:  $USER ADMIN=ALL JBP=ALL

Thanks in advance for any help.

jim

2. IPPPd Serversetup?

3. Matching Line After Pattern (Pattern Occurs Multiple Times)

4. Two Ethernet IF's One Subnet?

5. Pattern matching and extracting the data which matches the pattern

6. Can't Boot w/ SuSE 7.2 Rescue Disk

7. matching lines of pattern in a file

8. Kernel 2.0.31 memory leaks?

9. inserting lines before and after lines with matching pattern using sed?

10. remove matching partial lines from two files ...

11. Need to remove a line with a matching last name which appears in many files

12. Pattern Matching Not Working When Pattern Assign To A Variable

13. ksh pattern matching when pattern is in a variable