replace strings in a file using strings from another file
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
replace strings in a file using strings from another file
Hi,
I have a xml file.
Inside it, I have
<source> there are two houses <\source>
<translation> Há duas casas<\translation>.
(from english to portuguese)
I am using Qtlinguist.
I have already translated everything.
Now it is time to correct it.
I have already using sed and awk to create two files: source and translation.
I have used a spell checker in the file translation.
Now, I want to use the "strings" from the file translation to replace the strings inside the xml file.
For example:
<source> the sky is blue <\source>
<translation> o céu éh azzul <\translation>
In the file translation the phrase "o céu éh azzul" is not correct.
The correct is "o céu é azul".
you'll have to create a pattern to look for the misspelled words, then use the correct word to replace it algorithm. it will have to look at every word within the first file, one word at a time and then check each word seperatly against every word within the correct spelling file then when found replace it.
Code:
badWord="o cu h azzul"
goodWord="o cu azul"
newString=${String//"$badWord"/"$goodWord"}
NewVar=${var//search pattern/replace with}
that is Bash Shell Script...
Search Multiple Words / String Pattern Using grep Command
you'll have to create a pattern to look for the misspelled words, then use the correct word to replace it algorithm. it will have to look at every word within the first file, one word at a time and then check each word seperatly against every word within the correct spelling file then when found replace it.
Code:
badWord="o cu h azzul"
goodWord="o cu azul"
newString=${String//"$badWord"/"$goodWord"}
NewVar=${var//search pattern/replace with}
that is Bash Shell Script...
Search Multiple Words / String Pattern Using grep Command
readarray -t correto_array < correto.txt
readarray -t errado_array < errado.txt
for i in `seq 0 $((${#correto_array[@]}-1))`
do
sed -i.bak "s/${errado_array[$i]}/${correto_array[$i]}/" final.xml
echo $i
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.