lundi 18 avril 2016

Bash: Creating a file from two other

I currently working on script which can create new translate .php file from old version. I need help with I need help with this, because it does not work as it should ( especially awk from $translation ). The original version has a different arrangement of lines, new translations and < ?php, comments, if, space line etc.

my spript:

#!/bin/bash
orginal="$1"
translation="$2"
new="$3"
while read -r line
do
    if [ $line =~ ^<* ] || [ $line =~ ^/* ] || [ $line =~ ^" "* ] || [ -z $line ]; then
        echo $line >> $new
    elif grep -q $($line | awk '{ print $1 }') "$translation";
    then
        echo "$($line | awk '{ print $1 }') $($line | awk '{ print $2 }') $(cat $translation | grep $($line | awk '{ print $1 }') | awk '{ print $3 }')" >> $new
    else
        echo "$($line | awk '{ print $1 }') $($line | awk '{ print $2 }') "";" >> $new
    fi
done < "$orginal"

example of $orginal:

$_LANG['accountinfo'] = "Account Information";
$_LANG['accountstats'] = "Account Statistics";
$_LANG['addfunds'] = "Add Funds";
$_LANG['addfundsamount'] = "Amount to Add";
$_LANG['addfundsmaximum'] = "Maximum Deposit";
$_LANG['addfundsmaximumbalance'] = "Maximum Balance";

example of $translation:

$_LANG['accessdenied'] = "Odmowa dostępu";
$_LANG['account'] = "Twoje Konto";
$_LANG['accountinfo'] = "Informacje o Koncie";
$_LANG['accountoverview'] = "Przegląd Konta";
$_LANG['accountstats'] = "Statystyki Konta";
$_LANG['addfunds'] = "Dodaj Fundusze";

Aucun commentaire:

Enregistrer un commentaire