search and replace within string
Byron Clark
byron.clark at gmail.com
Thu May 17 12:16:36 MDT 2007
On 5/17/07, Wade Preston Shearer <lists at wadeshearer.com> wrote:
> I am curious how I would make searchFor and replaceWith variables.
>
> This…
>
> searchFor="search_for_text"
> replaceWith="replace_with_text"
> newString=$(echo $@ | sed 's/$searchFor/$replaceWith/')
> echo $newString
The following should work:
searchFor=search_for_text
replaceWith=replace_with_text
for s in $@; do
echo $(echo "${s}" | sed "s/${searchFor}/${replaceWith}/g")
done
More information about the PLUG
mailing list