0

I want to create with sed the following:

For example each word in the file that have the ssss... Should be replaced (all word) with target string as gggg.

echo "duwdbnhb ssssssmnfkejfnei" | sed s'/ssssss*/gggg/g'
duwdbnhb ggggmnfkejfnei

should be:

duwdbnhb gggg

remark - string could be with couple of s strings ( for example ss or sss or ssssss ...)

Example:

echo "duwdbnhb sssmnfkejfnei" | sed s'/s*/gggg/g'
duwdbnhb gggg

example A

echo "rf3 f34kf3ein3e ssghdwydgeug swswww ssswjdbuyhb" |  sed s'/ss.*/gggg/'

rf3 f34kf3ein3e gggg

but should print that:

rf3 f34kf3ein3e gggg swswww gggg

example B

echo "rf3 f34kf3ein3e ssghdwydgeug swswww ssswjdbuyhb" |  sed s'/s.*/gggg/'

rf3 f34kf3ein3e gggg

but should print that:

rf3 f34kf3ein3e gggg gggg gggg
0

If I understood correctly, you want to replace the each word beginning with 2 or more s-characters:

sed s'/ss[^[:blank:]]*/gggg/g'
  • see my update question – yael Jan 27 '16 at 12:15
  • @yael See my updated answer – chaos Jan 27 '16 at 12:17
  • From the word beginning \<ss[^[:blank:]]* or \bss\S* – Costas Jan 27 '16 at 16:59
0

You can do:

sed -r 's/(^|[[:blank:]])(ss[^[:blank:]]*)/\1gggg/g' file.txt

Example:

% echo "rf3 f34kf3ein3e ssghdwydgeug swswww ssswjdbuyhb" | sed -r 's/(^|[[:blank:]])(ss[^[:blank:]]*)/\1gggg/g' 
rf3 f34kf3ein3e gggg swswww gggg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.