Mailinglist Archive: opensuse (2800 mails)
| < Previous | Next > |
Re: [opensuse] Reg. expression
- From: Jan Karjalainen <jrock@xxxxxxx>
- Date: Thu, 08 Feb 2007 00:19:56 +0100
- Message-id: <45CA5E9C.5000404@xxxxxxx>
Randall R Schulz wrote:
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
Jan,I'm trying to parse through a file and delete all the lines with the word "LOG" on it, eg. replace it with "".
On Wednesday 07 February 2007 14:49, Jan Karjalainen wrote:
Brian Jackson wrote:
On Wednesday 07 February 2007 14:38, Jan Karjalainen wrote:
I'd like to go through a file and find all the lines with the wordgrep LOG [filename]
"LOG" in them.
How do I do that? Like "^(*[LOG]*)$" or what...?
I think you're trying to make this more complicated than it is. Now if you want LOG to be a word by itself, then:
grep ' LOG ' [filename]
Of if it can be at the beginning or end of a line...
grep '\bLOG\b' [filename]
I usually just use the "-w" option when I want to find the pattern only as a full word (i.e., be bounded on each end by either a line beginning or end or by a non-alphanumeric character).
% grep --help
...
-w, --word-regexp force PATTERN to match only whole words
...
Of course, the "\b" (and it's close relative, \B) is more flexible, giving you the ability to place the pattern at a word boundary on one end and not the other.
good luck,Thanks for the tip, but I knew about grep already.
brian
It's because of an application that has a search and replace function
which supports regular expressions...
Are you saying you need not simply to find the lines that contain "LOG" but also to apply some modification to such lines? Then you'll want "sed" or "awk" or possibly to use Perl.
Can you clarify what you need to accomplish? Based on your original question, Brian's answer seems correct and appropriate.
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
| < Previous | Next > |