Thanks Thanks:  1
Ergebnis 1 bis 3 von 3
  1. #1
    Mitglied Avatar von Lucifer
    Registriert seit
    01.02.2015
    Beiträge
    60
    Total Downloaded
    148,6 KB
    Total Downloaded
    148,6 KB
    ReceiverDankeAktivitäten

    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
    Avatar von Pike_Bishop
    Registriert seit
    05.09.2013
    Ort
    here and there
    Beiträge
    2.312
    Total Downloaded
    155,15 MB
    Total Downloaded
    155,15 MB
    ReceiverDankeAktivitäten
    Box 1:
    Clarke-Tech ET9000
     
     
    Box 2:
    Mutant HD 2400
     
     
    Box 3:
    VDR
     
     
    Box 4:
    VDR
     
     
    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)
    Openmultiboot, OpenPLI-4.0, und OpenATV-6.0

  3. Thanks Lucifer bedankten sich
  4. #3
    Mitglied Avatar von Lucifer
    Registriert seit
    01.02.2015
    Beiträge
    60
    Themenstarter
    Total Downloaded
    148,6 KB
    Total Downloaded
    148,6 KB
    ReceiverDankeAktivitäten
    Thanks Pike, i will make a test later this week.
    i really like the log file too, it's a good idea.

    grt Lucifer


Stichworte

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  
Diese Website benutzt Cookies
Wir benutzen Cookies um Sitzungsinformationen zu speichern. Dies erleichtert es uns z.B. Dich an Deine Login zu erinnern, Einstellungen der Webseite zu speichern, Inhalte und Werbung zu personalisieren, Social Media Funktionen anzubieten und unser Datenaufkommen zu analysieren. Wir teilen diese Informationen ebenfalls mit unseren Social Media-, Werbe- und Analysepartnern.
     
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:40 Uhr.
Powered by vBulletin® Version 4.2.3 (Deutsch)
Copyright ©2017 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