LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-22-2016, 11:56 AM   #1
xpto09
LQ Newbie
 
Registered: Oct 2007
Posts: 20

Rep: Reputation: 0
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".

All the translations are in lines.

How do I do this?
 
Old 01-22-2016, 03:33 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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

how to search through files until getting one linux

http://unix.stackexchange.com/questi...-within-a-line

Last edited by BW-userx; 01-22-2016 at 03:41 PM.
 
Old 01-28-2016, 06:02 PM   #3
xpto09
LQ Newbie
 
Registered: Oct 2007
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by BW-userx View Post
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

how to search through files until getting one linux

http://unix.stackexchange.com/questi...-within-a-line

I tried this:

Code:
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
using google and
http://http://stackoverflow.com/ques...rd-file-solved

However, the file to be changed is xml file.
Sed has a problem with certain characters .

Could you translate my code to a bash script?

Last edited by xpto09; 01-28-2016 at 07:43 PM.
 
Old 01-28-2016, 06:11 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by xpto09 View Post


However, the file to be changed is xml file.
Sed has a problem with certain characters .

Could you translate my code to a bash script?
start looking into programs that are good for parsing xml files.. one I found in another fourm is called XMLLINT --

Find and Replace Values in XML using Python

sorry, I have no idea personally how to deal with xml.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
search replace multiple strings in a file fundoo.code Linux - Newbie 10 09-24-2015 09:31 PM
Search and replace strings with file paths in vim geeksquads Linux - Software 2 01-30-2015 02:03 AM
BASH: replace strings in on file by the strings in another one cristalp Programming 5 10-28-2011 09:47 AM
[SOLVED] Searching and replacing strings in a file with strings in other files xndd Linux - Newbie 16 07-29-2010 02:40 PM
bash: how to replace strings of a file with some " chars ? frenchn00b Linux - General 1 03-01-2008 09:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration