simple sed question

hi
is it possible to cut this two semicolon separated sed commands
echo "string2 string3 string1" | sed s'/string1//g;s/string2//g'
output: " string3 "

to just one sed command without semicolon?

thanks in advance

funksen

if what you want is only "string3" ,why not use cut

 # echo "string2 string3 string1" | cut -d " " -f2
string3

thanks,

that was just an example, I want to cut out two or more strings out of a line or replace it with any other string I specify

what I want two know is how to combine search strings, like find string1 and string2 and string3 and replace all of them with the same string, and all in the same sed command

like sed 's/string1 AND string2 AND string3/string4/g'
should replace any appearance of string1, string2 and string3 with the same string, string4
which can be in any order in one line, with 100 other strings
hope its clear what I mean

funksen,
There are a few ways of doing what you want, but here is one using one sed statement as you requested:
sed -e's/string1/newstring/g' -e's/string2/newstring/g' -e's/string3/newstring/g' input_file

thanks shell_life

that is almost the same statement that I wrote in the topic, so is there no way to merge this three commands into one with some kind of separator in the first field?

echo "string1 string2 string3" | sed "s/string[1-3]/newstring/g"

echo "string1 string2 string3" | sed "s/string[1-3]/newstring/g"

hehe thats nice, but as you can imagine, the strings don't really are string1 string2 and string3, they could be aAdfg f2gjwer and tzez_u

but ok, thanks for all your answers, seems as there is really no way

This is one way you can use it

 # change "scarlet" or "ruby" or "puce" to "red"
 sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g'   # most seds
 gsed 's/scarlet\|ruby\|puce/red/g'                # GNU sed only

A reference to sed 1-liners would be appropriate for the quote.

thanks a lot srikanthus2002, this is exactly what I was looking for

it's working here on my fc6 desktop as I expected, I hope its working on my unix machines too (but I don't think so)

cheers,

funksen