Reputation: 21
I'm trying to remove lines from the output that contains "xyz" in 1st column using awk as
grep -H --with-filename "Rule" *| awk '$1!=" \*xyz\* "{print $0}'
but I'm not having any success with this.
For example after doing grep -H --with-filename "Rule"
I'm getting the output as
file_xyz.log abc p12r
file1.log asd ef23t
fi_xyz.log gbc or26r
file1.log asd ef2t
but I want to remove all lines which contain xyz
.
Upvotes: 1
Views: 110
Reputation: 203209
Some notes on your question:
awk
syntax, you should find an intro to awk
tutorial or read a few pages of the manual to get started. I highly recommend everyone get the book Effective Awk Programming, 4th Edition, by Arnold Robbins
.grep
man page will tell you that -H
and --with-filename
are the short and long versions of exactly the same option - you don't need to use both, just one of them.Rule
doesn't appear anywhere in the output you say you get when grep-ing for Rule
and grep -H
will output a :
after the file name while you show a blank - make sure your input, output, and code are consistent and correct when asking a question.grep
when you're using awk
.This is probably all you need:
awk '(FILENAME !~ /xyz/) && /Rule/{print FILENAME, $0}' *
but there are also ways in some shells (see https://unix.stackexchange.com/q/164025/133219 and https://unix.stackexchange.com/q/335484/133219 for bash
examples) to specify a globbing pattern that excludes some strings so then you never open them to search inside in the first place.
Upvotes: 1