Denis Chmel
Denis Chmel

Reputation: 789

Shell command/workaround to turn quoted strings into normal strings

I'm writing a shell script that outputs all untranslated strings from gettext .po file, and stuck on a simple thing. At the end of my commands chain I get such output:

"less than a minute left"
"%d minutes left"
"logged in as <a href=\"%s\">%s</a>"
"more"

And I don't know how to echo these lines without quotes, like this:

less than a minute left
%d minutes left
logged in as <a href="%s">%s</a>
more

Note, that quotes are used inside phrases, so I can't just remove them by sed. I wish I knew a command that unquotes such. Something more injection-safe than

 awk '{ print "echo ", $0}' | sh

Just in case here's a working demo of what I have so far:

 wget https://raw.github.com/vslavik/poedit/master/locales/wa.po
 msgattrib --untranslated --no-wrap wa.po | grep msgid | sed "s/msgid[^ ]*//"

Upvotes: 0

Views: 116

Answers (2)

Kent
Kent

Reputation: 195209

i guess this should be ok:

msgattrib --untranslated --no-wrap wa.po | grep msgid | sed "s/msgid[^ ]*//"|sed -e 's/^\s"//' -e 's/"$//'

edit

this time?

    msgattrib --untranslated --no-wrap wa.po | grep msgid | sed "s/msgid[^ ]*//"\
|sed -e 's/^\s"//' -e 's/"$//' -e's/\\"/"/g'

Upvotes: 1

Andrew Clark
Andrew Clark

Reputation: 208575

Adding 's/^\s"\|"$//g' and 's/\\"/"/g' to your sed command should strip off the leading and trailing ", and also convert all \" to ".

Full command:

msgattrib --untranslated --no-wrap wa.po | grep msgid | sed 's/msgid[^ ]*//; s/^\s"\|"$//g; s/\\"/"/g'

Upvotes: 1

Related Questions