Results 1 to 2 of 2
Hello everyone! I am making a script to replace text lines, my idea is use the script to translate subtitles files in english to spanish, i am thinking to use ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-20-2011 #1
- Join Date
- Sep 2011
how do i replace text lines?
I am making a script to replace text lines, my idea is use the script to translate subtitles files in english to spanish, i am thinking to use Bash script with sed instrucctions, But i not sure if Sed can replace text lines on one file with other text lines from another file. there Is posible to do that? Or what alternative method do you recomend me?
- 09-22-2011 #2
- Join Date
- May 2011
Certainly sed can do that, that is its specialty. You'd need to work out how the equivalent English is converted to Spanish, but once you have that, you can do something like:
sed -i.bak 's/^.*$LINE_IN_ENGLISH.*$/$SPANISH_TRANSLATION/' myfile.txt
1. your text containing the lines in English is in myfile.txt
2. the specific line in English to translate is saved to the variable $LINE_IN_ENGLISH
3. the Spanish translation of that is saved to the variable $SPANISH_TRANSLATION
The ^.* and .*$ sed code just tells sed to match anything else at the beginning and end of that line.
The -i.bak switch tells sed to do an in-file substitution (instead of printing the change to STDOUT) and to make a backup of the original file using the ".bak" extension (so myfile.txt.bak would get created).