Find the answer to your Linux question:
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.
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Location
    Argentina
    Posts
    11

    how do i replace text lines?


    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 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?

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    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:

    Code:
    sed -i.bak 's/^.*$LINE_IN_ENGLISH.*$/$SPANISH_TRANSLATION/' myfile.txt
    This assumes that:
    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •