mercredi 7 juin 2017

Search and replace of several sentences using bash

now, i have script to search and replace words. How can i do the same for sentences or wordcombinations. Look on my script:

first_words="wwe wwf ziggler"
second_words="tna njpw okada"

mywords=( $first_words )
mywords2=( $second_words )

if [ ${#mywords[@]} != ${#mywords2[@]} ];then
        echo "you should use the same count of words"
        exit 1
else
        echo "you are using the same count of words, continue ..."
fi

for ((i=0;i<"${#mywords[@]}";++i)); do
        sed -i "s/${mywords[$i]}/${mywords2[$i]}/g" text.txt
done

It works, but only replace words by word. But if i want to replace several wordcombinations on several wordcombinations. For example "dolph ziggler, john cena, randy orton" i want to replace on "cm punk, hulk hogan, rey mysterio". What i should do in this situnation. May be i should handle some delimiter. In first case, the space was delimiter for words, but in this situation, i can't use space. What i can do ? Please help.

Aucun commentaire:

Enregistrer un commentaire