Find several different words and replace with one using sed.
So as my title says, im trying to match multiple words and replace them all with one.
I have tried "test|just|this" in my regex checker app and it matches all 3 words, but when I try use it in the sed command it doesn't match any... What am I doing wrong here? Code:
echo This is just quick little test | sed 's/test|just|this/./i' I would appreciate some help here. |
Wrong tool for the job - spanners make poor screwdrivers.
|
Quote:
|
use awk
Code:
echo This is just quick little test | awk '{gsub(/test|just|this/,"")}1' |
Fantastic, thanks ghostdog74.
That does exactly what I need it to do. I did have a quick look at the awk man pages (at the examples) but it didn't really seem like the right thing at the time, but now I know it is. |
Quote:
|
Another happy customer - cheers ghostdog74.
Dammit, you're going to make everybody awk users .... :p |
I'v opened tabs on nearly all of the links in your sig :)
Just one more quick question, How would I do a case insensitive match? (with sad I could just go /i but it's not so easy with awk as far as i'v seen) I had a little read from the link in your sig... I don't get how it work? or how im supposed to use it. .... Code:
echo This is just quick little test | awk 'tolower($1) ~ {gsub(/test|just|this|\ /,".")}1' |
like i said , read the link. If you do, you will come across IGNORECASE. Set it to 1.
|
Well Sed also works take a look at this snippet
Code:
|
Quote:
one of the things good about learning awk, is that you can totally skip learning sed, since their capabilities overlap (and awk is a small programming language itself) |
Quote:
Quote:
So, would you or someone else have any pointers as to how I would get it to work the other way (as stated in my previous post.) |
Inspired by ghostdog :-)
Code:
echo This is just quick little test | awk 'IGNORECASE = 1 {gsub(/test|just|this/,".")}1' |
Quote:
Each to their own ... |
Quote:
|
Quote:
Code:
# echo This is just quick little test | awk 'IGNORECASE = 1 {gsub(/test|just|this/,".")}1' It doesn't work. (running Debian 5 Code:
# awk -W version Never mind, I just updated it, and it works now! Thanks! Code:
# awk -W version |
Well Techno Guy,
It worked for me I am beginner to awk ghostdog might answer your quesiton, you can use sed option that i have given or Code:
echo This is just quick little test | perl -e 'while (<>) { s/this|just|test/./ig; print}' |
IGNORECASE is gawk feature. if there is no way you can use gawk, then no choice, use tolower()
|
Quote:
All works fine now. Thanks so much for your help guys. You guys have overwhelmed me with options :) Until next time :) |
All times are GMT -5. The time now is 06:47 PM. |