Hi,
I am looking for regex to extract following words from text:
The word which comes after "Replaced" means
Replaced disk
Replaced floppy
Replaced memory
Please suggest the regex for it.
Thanks!
Hi,
I am looking for regex to extract following words from text:
The word which comes after "Replaced" means
Replaced disk
Replaced floppy
Replaced memory
Please suggest the regex for it.
Thanks!
You're a bit unclear as to what the format of the input exactly is. Assuming that it consists of newline separated records, and the only thing from the file that you want printed is the text after the word "Replaced", and that the word "Replaced" is the first word on the line, then this should work:
sed -n '/^[ \t]*Replaced/ !b; s/^[ \t]*Replaced //; p' input-file >output-file
If there are words after "disk," "memory," or what ever that should be deleted too, then this should work:
sed -n '/^[ \t]*Replaced/ !b; s/^[ \t]*Replaced //; s/ .*//; p' input-file >output-file
"Replaced (\w+)"
The fine details depend on how you want to do this: grep? awk?... anything on the command line? ...
Thanks guys
I tried Replaced (\w+) but it is working when "replaced" is a first word of text.
But if the word is coming in middle of text then regex is not working.
Please suggest !!!
I think you should start by telling us which regex implementation you'd be using. Sed, awk, perl, grep... What is the input file (comprising of different scenarios)? What is the desired output?