echo "bla bla word word1 = string1 string2" | sed -e 's/.* \([^ ]*\)=.*/\1/g' Some basic regexp hints: the first /…/ is what your string should match s means substitute/replace the last /…/ is the replacement g means global, replace all occurrences a . will…