2013-10-02 4 views
0

У меня есть файл структурирован следующим образом:своп две строки сценария

msgid "" 
    msgstr "" 
    "PO-Revision-Date: 2013-04-08 10:12:14+0000\n" 
    "MIME-Version: 1.0\n" 
    "Content-Type: text/plain; charset=UTF-8\n" 
    "Content-Transfer-Encoding: 8bit\n" 
    "Plural-Forms: nplurals=2; plural=n > 1;\n" 
    "X-Generator: GlotPress/0.1\n" 
    "Project-Id-Version: Modern Theme\n" 

    #: 404.php:34 
    msgid "Page not found" 
    msgstr "Page non trouvée" 

    #: alert-form.php:6 
    msgid "You have sucessfully subscribed to the alert" 
    msgstr "Vous vous êtes inscrit avec succès à cette alerte" 

    #: alert-form.php:7 user-change_email.php:42 
    msgid "Invalid email address" 
    msgstr "Adresse e-mail incorrecte" 

    #: alert-form.php:8 
    msgid "There was a problem with the alert" 
    msgstr "Il y a un problème avec cette alerte" 

    #: alert-form.php:39 
    msgid "Subscribe to this search" 
    msgstr "Abonnez vous à cette recherche" 

    #: alert-form.php:55 
    msgid "Subscribe now" 
    msgstr "Abonnez-vous maintenant" 

    #: contact.php:35 
    msgid "Contact us" 
    msgstr "Contactez-nous" 

Я хотел бы поменять содержание, линии, чем содержать строку MsgId, между кронштейнами с содержанием, по последовательной линии которые содержат msgstr, между скобками, можете ли вы дать мне подсказку написать сценарий или сделать это через командную строку?

+0

почему вы не просто поменять '' msgid' с msgstr' или у вас есть, чтобы сохранить свою позицию относительно? –

+0

Да так напр: MSGID «Страница не найдена» пакетов «страницы, не являющейся trouvée» стать: MSGID «Страница не trouvée» пакетов «Страница не найдена» – molwiko

+0

То есть то же самое! –

ответ

2

Вы можете использовать awk и sed для этого. Следующие работы.

awk '/msg.*/{getline x;print x;}1' file | sed -e 's/msgid/msgidt/g' -e 's/msgstr/msgid/g' -e 's/msgidt/msgstr/g' 

awk обменивает строки, который соответствует регулярному выражению с msg.* и трубами его к sed. Сначала sed переименовывает msgid во временный msgidt, а затем переименовывает msgstr в msgid и, наконец, msgidt в msgid.

Результат:

msgid "" 
msgstr "" 
"PO-Revision-Date: 2013-04-08 10:12:14+0000\n" 
"MIME-Version: 1.0\n" 
"Content-Type: text/plain; charset=UTF-8\n" 
"Content-Transfer-Encoding: 8bit\n" 
"Plural-Forms: nplurals=2; plural=n > 1;\n" 
"X-Generator: GlotPress/0.1\n" 
"Project-Id-Version: Modern Theme\n" 

#: 404.php:34 
msgid "Page non trouvee" 
msgstr "Page not found" 

#: alert-form.php:6 
msgid "Vous vous Cetes inscrit avec succsess cette alerte" 
msgstr "You have sucessfully subscribed to the alert" 

#: alert-form.php:7 user-change_email.php:42 
msgid "Adresse e-mail incorrecte" 
msgstr "Invalid email address" 

#: alert-form.php:8 
msgid "Il y a un problC(me avec cette alerte" 
msgstr "There was a problem with the alert" 

#: alert-form.php:39 
msgid "Abonnez vous C cette recherche" 
msgstr "Subscribe to this search" 

#: alert-form.php:55 
msgid "Abonnez-vous maintenant" 
msgstr "Subscribe now" 

#: contact.php:35 
msgid "Contactez-nous" 
msgstr "Contact us" 
+0

Спасибо Мне нужно сохранить вывод на файл с iso-8859-1 Я попытался файл, но он был сохранен на UTF-8? – molwiko

+0

Вы можете использовать 'iconv -f UTF-8 -t ISO-8859-1 in.txt> out.txt' – iamauser

Смежные вопросы