Seite 1 von 2 12 LetzteLetzte
Ergebnis 1 bis 10 von 11
  1. #1
    Senior Mitglied Avatar von Lucifer
    Registriert seit
    01.02.2015
    Beiträge
    184
    Thanks (gegeben)
    134
    Thanks (bekommen)
    131
    Total Downloaded
    1,62 MB
    Total Downloaded
    1,62 MB
    ReceiverDanke

    How to 'filter' on two lines, in a file ?

    Hi, i'm trying to 'filter' a .po file, and make some replacements.

    This is how it looks in the original test.po file:

    msgid "ORIGINAL-1"
    msgstr "TRANSLATION-1"


    msgid "ORIGINAL-2"
    msgstr "TRANSLATION-1"


    msgid "ORIGINAL-3"
    msgstr "TRANSLATION-1"


    when i do this:

    How to 'filter' on two lines, in a file ?-code1.png

    it looks like this:

    msgid "ORIGINAL-1"
    msgstr "TRANSLATION-2"


    msgid "ORIGINAL2"
    msgstr "TRANSLATION-2"


    msgid "ORIGINAL3"
    msgstr "TRANSLATION-2"


    but this is how i want it to become:

    msgid "ORIGINAL-1"
    msgstr "TRANSLATION-2"


    msgid "ORIGINAL2"
    msgstr "TRANSLATION-3"


    msgid "ORIGINAL3"
    msgstr "TRANSLATION-4"


    so, i tried to connect and 'filter' on two lines, like this:

    How to 'filter' on two lines, in a file ?-code2.png

    but this doesn't work.

    is it possible to connect and 'filter' on two lines, when the second is a new line ?
    if so, how to formulate it ?


    grt Lucifer
    Miniaturansichten angehängter Grafiken Miniaturansichten angehängter Grafiken How to 'filter' on two lines, in a file ?-code1.png   How to 'filter' on two lines, in a file ?-code2.png  

    Geändert von Lucifer (29.04.2017 um 21:24 Uhr) Grund: missing text

    •   Alt Advertising

       

  2. #2
    Pike_Bishop
    Gast
    Hi Lucifer,

    it looks like this:

    msgid "ORIGINAL-1"
    msgstr "TRANSLATION-2"


    msgid "ORIGINAL2"
    msgstr "TRANSLATION-2"


    msgid "ORIGINAL3"
    msgstr "TRANSLATION-2"
    that's correct - sed replaces all hits in the file if you set the option g for global
    otherwise without g it replaces one hit each line, so in your case you become the same result also without g

    if you want to become that;
    but this is how i want it to become:

    msgid "ORIGINAL-1"
    msgstr "TRANSLATION-2"


    msgid "ORIGINAL2"
    msgstr "TRANSLATION-3"


    msgid "ORIGINAL3"
    msgstr "TRANSLATION-4"
    then try this;
    Code:
    #!/bin/bash
    
    ## Variablen ##
    TMP=/tmp
    TARGETFILE=$TMP/originalpo.txt
    BACKUPFILE=$TMP/originalpo-backup.txt
    LOGFILE=$TMP/testing.log
    
    
    # Logfile loeschen (remove logfile).
    rm -f $LOGFILE
    
    
    # Generelles Logging (general logging).
    exec 3>&1 4>&2
    trap 'exec 2>&4 1>&3' 0 1 2 3
    exec 1>$LOGFILE 2>&1
    
    
    # Original Datei sichern (backup original file).
    if [ ! -e $BACKUPFILE ] ; then
        cp $TARGETFILE $BACKUPFILE
    fi
    
    # Job beginnt (job begins).
    TRANSLATION="msgstr \"TRANSLATION-"
    TRANSL_COUNT=1
    for line in $(grep -n "\<msgstr\>" $TARGETFILE | cut -d: -f1) ; do
        let ++TRANSL_COUNT
        echo -e "\nline to replace = line $line"
        NEW_TRANSLATION="$TRANSLATION$TRANSL_COUNT\""
        echo -e "\nNEW_TRANSLATION for line $line = $NEW_TRANSLATION"
        sed -i -e "${line}c$NEW_TRANSLATION" $TARGETFILE;
    done
    
    exit
    here it works .
    it works with the line numbers in a loop and i have build in first to backup the original file and also logging.
    i have test it with a file with name originalpo.txt in the directory /tmp on my box, it looks as following;
    Code:
    sgid "ORIGINAL-1"
    msgstr "TRANSLATION-1"
    
    
    msgid "ORIGINAL-2"
    msgstr "TRANSLATION-1"
    
    
    msgid "ORIGINAL-3"
    msgstr "TRANSLATION-1"
    
    
    msgid "ORIGINAL-4"
    msgstr "TRANSLATION-1"
    
    
    msgid "ORIGINAL-5"
    msgstr "TRANSLATION-1"
    
    
    msgid "ORIGINAL-6"
    msgstr "TRANSLATION-1"
    
    
    msgid "ORIGINAL-7"
    msgstr "TRANSLATION-1"
    
    
    msgid "ORIGINAL-8"
    msgstr "TRANSLATION-1"
    
    
    msgid "ORIGINAL-9"
    msgstr "TRANSLATION-1"
    after use of the script it looks as following;
    Code:
    msgid "ORIGINAL-1"
    msgstr "TRANSLATION-2"
    
    
    msgid "ORIGINAL-2"
    msgstr "TRANSLATION-3"
    
    
    msgid "ORIGINAL-3"
    msgstr "TRANSLATION-4"
    
    
    msgid "ORIGINAL-4"
    msgstr "TRANSLATION-5"
    
    
    msgid "ORIGINAL-5"
    msgstr "TRANSLATION-6"
    
    
    msgid "ORIGINAL-6"
    msgstr "TRANSLATION-7"
    
    
    msgid "ORIGINAL-7"
    msgstr "TRANSLATION-8"
    
    
    msgid "ORIGINAL-8"
    msgstr "TRANSLATION-9"
    
    
    msgid "ORIGINAL-9"
    msgstr "TRANSLATION-10"
    and the logfile thereto looks as following;
    Code:
    line to replace = line 2
    
    NEW_TRANSLATION for line 2 = msgstr "TRANSLATION-2"
    
    line to replace = line 6
    
    NEW_TRANSLATION for line 6 = msgstr "TRANSLATION-3"
    
    line to replace = line 10
    
    NEW_TRANSLATION for line 10 = msgstr "TRANSLATION-4"
    
    line to replace = line 14
    
    NEW_TRANSLATION for line 14 = msgstr "TRANSLATION-5"
    
    line to replace = line 18
    
    NEW_TRANSLATION for line 18 = msgstr "TRANSLATION-6"
    
    line to replace = line 22
    
    NEW_TRANSLATION for line 22 = msgstr "TRANSLATION-7"
    
    line to replace = line 26
    
    NEW_TRANSLATION for line 26 = msgstr "TRANSLATION-8"
    
    line to replace = line 30
    
    NEW_TRANSLATION for line 30 = msgstr "TRANSLATION-9"
    
    line to replace = line 34
    
    NEW_TRANSLATION for line 34 = msgstr "TRANSLATION-10"

    regards
    Pike
    Geändert von Pike_Bishop (16.05.2017 um 19:01 Uhr)

  3. Thanks Lucifer bedankten sich
  4. #3
    Senior Mitglied Avatar von Lucifer
    Registriert seit
    01.02.2015
    Beiträge
    184
    Thanks (gegeben)
    134
    Thanks (bekommen)
    131
    Themenstarter
    Total Downloaded
    1,62 MB
    Total Downloaded
    1,62 MB
    ReceiverDanke
    Thanks Pike, i will make a test later this week.
    i really like the log file too, it's a good idea.

    grt Lucifer

  5. #4
    Senior Mitglied Avatar von Lucifer
    Registriert seit
    01.02.2015
    Beiträge
    184
    Thanks (gegeben)
    134
    Thanks (bekommen)
    131
    Themenstarter
    Total Downloaded
    1,62 MB
    Total Downloaded
    1,62 MB
    ReceiverDanke
    @Pike_Bishop,
    Hi Pike, i finally had the time to test the script.
    the script works perfectly when the strings with numbers are used.
    but the strings like "ORIGINAL-1", "ORIGINAL-2", ... and "TRANSLATION-1", "TRANSLATION-2", ... are only there for example.


    these are the real strings that i want to change:


    msgid "Plugins"
    msgstr "Plugins"


    msgid "Extensions"
    msgstr "Plugins"


    msgid "extensions"
    msgstr "Plugins"

    i want to change them into:


    msgid "Plugins"
    msgstr "Plugins"


    msgid "Extensions"
    msgstr "Extensies"


    msgid "extensions"
    msgstr "extensies"

    in the testscript you made, you did make use of the line numbers.
    maybe that can be the solution for the for the script.


    search for this string:msgid "Extensions", remove next line, write new line:msgstr "Extensies"
    search for this string:msgid "extensions", remove next line, write new line:msgstr "extensies"


    grt Luciter

  6. #5
    Pike_Bishop
    Gast
    but the strings like "ORIGINAL-1", "ORIGINAL-2", ... and "TRANSLATION-1", "TRANSLATION-2", ... are only there for example.
    i know
    i think you need a additional loop as example;
    Code:
    while read line ; do
    
    done < /tmp/file_with_translations.txt
    and in this loop you can put in the loop from post #2 this one;
    Code:
    TRANSLATION="msgstr \"TRANSLATION-"
    TRANSL_COUNT=1
    for line in $(grep -n "\<msgstr\>" $TARGETFILE | cut -d: -f1) ; do
        let ++TRANSL_COUNT
        echo -e "\nline to replace = line $line"
        NEW_TRANSLATION="$TRANSLATION$TRANSL_COUNT\""
        echo -e "\nNEW_TRANSLATION for line $line = $NEW_TRANSLATION"
        sed -i -e "${line}c$NEW_TRANSLATION" $TARGETFILE;
    done
    you can read line for line from a file with your new translations
    this you can do with the while read loop and
    after a line was read you must to allocate the line to the variable $NEW_TRANSLATION
    for the second loop, but you must also change things in the second loop a little bit.

    it's sure doable but it's a bit complcated.
    for what is that good ?
    earlier i also translated many things but i didn't need a script for that.


    regards
    Pike
    Geändert von Pike_Bishop (05.06.2017 um 17:42 Uhr)

  7. #6
    Senior Mitglied Avatar von Lucifer
    Registriert seit
    01.02.2015
    Beiträge
    184
    Thanks (gegeben)
    134
    Thanks (bekommen)
    131
    Themenstarter
    Total Downloaded
    1,62 MB
    Total Downloaded
    1,62 MB
    ReceiverDanke
    Thanks Pike,
    i made a script to change a translation file automatically, incase of an update.
    it saves a lot of time.
    i can do all the changes this way, accept for the last two that are Translated with "Plugins"
    and because i only know a little bit about bash commands/scripts i was wondering if it could be done (easy) with a script.

    it's not a big problem, it are only two translations, and it doesn't take much time to change two translations manually.
    but if it can be done, it would be nice, and i can learn someting more about the possibilities of scripts.

    grt Lucifer
    Geändert von Lucifer (05.06.2017 um 21:27 Uhr) Grund: missing space

  8. #7
    Pike_Bishop
    Gast
    Hi Lucifer,

    i can do all the changes this way, accept for the last two that are Translated with "Plugins"
    then you already have a working script ? if yes can i see it ?


    regards
    Pike

  9. #8
    Senior Mitglied Avatar von Lucifer
    Registriert seit
    01.02.2015
    Beiträge
    184
    Thanks (gegeben)
    134
    Thanks (bekommen)
    131
    Themenstarter
    Total Downloaded
    1,62 MB
    Total Downloaded
    1,62 MB
    ReceiverDanke
    Hi Pike,
    here is the script.

    the method that i use to replace the lines comes from a postinst script of a plugin ipk package.
    in the postinst script the method is used to make changes in the keymap (usr/share/enigma2/keymap.xml)

    grt Lucifer
    Angehängte Dateien Angehängte Dateien

  10. #9
    Pike_Bishop
    Gast
    Hi Lucifer,

    i made a solution as following;
    Code:
    #!/bin/bash
    
    ## Variablen ##
    TMP=/tmp
    TARGETFILE=$TMP/originalpo.txt
    BACKUPFILE=$TMP/originalpo-backup.txt
    LOGFILE=$TMP/testing.log
    
    
    # Logfile loeschen (remove logfile).
    rm -f $LOGFILE
    
    
    # Generelles Logging (general logging).
    exec 3>&1 4>&2
    trap 'exec 2>&4 1>&3' 0 1 2 3
    exec 1>$LOGFILE 2>&1
    
    
    # Original Datei sichern (backup original file).
    if [ ! -e $BACKUPFILE ] ; then
        cp $TARGETFILE $BACKUPFILE
    fi
    
    
    # Job beginnt (job begins).
    EXTENS_1="msgid \"Extensions\""
    TO_WRITE_1="msgstr \"Extensies\""
    LINE_TO_REMOVE_1="$(grep -n "$EXTENS_1" "$TARGETFILE" | cut -d: -f1)"
    let ++LINE_TO_REMOVE_1
    echo -e "\nline (old translation) to remove = line $LINE_TO_REMOVE_1."
    sed -i -e ''"$LINE_TO_REMOVE_1"'d' "$TARGETFILE"
    echo -e "\nwrite new translation;\n$TO_WRITE_1\nin line $LINE_TO_REMOVE_1."
    sed -i -e '/'"$EXTENS_1"'/{;a\' "$TARGETFILE" -i -e "$TO_WRITE_1" -i -e '}'
    
    EXTENS_2="msgid \"extensions\""
    TO_WRITE_2="msgstr \"extensies\""
    LINE_TO_REMOVE_2="$(grep -n "$EXTENS_2" "$TARGETFILE" | cut -d: -f1)"
    let ++LINE_TO_REMOVE_2
    echo -e "\nline (old translation) to remove = line $LINE_TO_REMOVE_2."
    sed -i -e ''"$LINE_TO_REMOVE_2"'d' "$TARGETFILE"
    echo -e "\nwrite new translation;\n$TO_WRITE_2\nin line $LINE_TO_REMOVE_2."
    sed -i -e '/'"$EXTENS_2"'/{;a\' "$TARGETFILE" -i -e "$TO_WRITE_2" -i -e '}'
    
    
    exit
    for test you can put the script on your box to the directory /tmp and name it as example test.sh and with bash /tmp/test.sh in telnet you can start it.
    it's with logging and first for the following two translations only;
    Code:
    msgid "Extensions"
    msgstr "Plugins"
    
    msgid "extensions"
    msgstr "Plugins"
    if you need more translations then you can see now how it works in the script.
    it works with grep which is readout the line (old translation) that must be remove with sed and parameter d
    , after the line was removed sed put in a new line (new translation) after the address which sed has found - this works with parameter a
    so sed search for a address as example msgid "Extensions" and put in a new line in the next line after the adress - it works good here i have test it.

    here now the testfile with name originalpo.txt that i used (i put it on my e2box in the directory /tmp);
    Code:
    msgid "Plugins"
    msgstr "Plugins"
    
    msgid "test"
    msgstr "testing"
    
    msgid "Other Test"
    msgstr "othertest"
    
    msgid "Extensions"
    msgstr "Plugins"
    
    msgid "More Test"
    msgstr "moretest"
    
    msgid "extensions"
    msgstr "Plugins"
    
    msgid "last test"
    msgstr "lasttest"
    after using the script it looks as following;
    Code:
    msgid "Plugins"
    msgstr "Plugins"
    
    msgid "test"
    msgstr "testing"
    
    msgid "Other Test"
    msgstr "othertest"
    
    msgid "Extensions"
    msgstr "Extensies"
    
    msgid "More Test"
    msgstr "moretest"
    
    msgid "extensions"
    msgstr "extensies"
    
    msgid "last test"
    msgstr "lasttest"
    an at last the logfile;
    Code:
    line (old translation) to remove = line 11.
    
    write new translation;
    msgstr "Extensies"
    in line 11.
    
    line (old translation) to remove = line 17.
    
    write new translation;
    msgstr "extensies"
    in line 17.

    regards
    Pike
    Geändert von Pike_Bishop (07.06.2017 um 17:11 Uhr)

  11. Thanks Lucifer bedankten sich
  12. #10
    Senior Mitglied Avatar von Lucifer
    Registriert seit
    01.02.2015
    Beiträge
    184
    Thanks (gegeben)
    134
    Thanks (bekommen)
    131
    Themenstarter
    Total Downloaded
    1,62 MB
    Total Downloaded
    1,62 MB
    ReceiverDanke
    Hi Pike,

    Thank you again my friend, it works perfectly
    i understand how it works now.

    one more question:
    some scripts end with 'exit' and some with 'exit 0'
    whats the difference, and when to use which ?

    grt Lucifer


Seite 1 von 2 12 LetzteLetzte

Stichworte

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:36 Uhr.
Powered by vBulletin® Version 4.2.5 (Deutsch)
Copyright ©2024 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.
Resources saved on this page: MySQL 5,26%
Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)
vBulletin Skin By: PurevB.com