在我的Localizable.Strings中,我试着让所有对按字母顺序排列。是否可以按字母顺序重新排序我的Localizable.strings?Maby使用genstring还是特殊bash脚本?
这里我还有额外的要求要完成:
1.排序应不区分大小写。
2.第十行(例如五行)应复制,而不是订购。
这一要求应该得到满足,因为在Localized.strings文件中,我有作者、公司名称和产品名称作为评论。
3.保留意见
我希望保留对翻译的字符串的注释,并在每个翻译之间保留新的行。这个注释是由iOS开发人员的特殊genstring命令生成的(例如,find ./ -name "*.m" -print0 | xargs -0 genstrings -o en.lproj查找我的代码中的所有NSLocalizedString(@"Param",@"Comment")并生成成对的/* Comment */ /r/n "Param" = "Param";文件)。翻译前的注释行是可选的,可能只有1行。例如,文件:
/* This is Billy */
"Billy" = "The smartest guy in the univererse";
/* The Hitchhiker's Guide to the Galaxy */
"42" = "the answer to life the universe and everything";
"Johny" = "Johny";
/* Optional field */
"Anny" = "Anny";产出应是:
/* The Hitchhiker's Guide to the Galaxy */
"42" = "the answer to life the universe and everything";
/* Optional field */
"Anny" = "Anny";
/* This is Billy */
"Billy" = "The smartest guy in the univererse";
"Johny" = "Johny";这个问题是我自己问题的更复杂的变体,您可以在这里找到:Reorder .strings file
发布于 2014-11-28 11:13:24
你觉得这是你想要的
在awk
awk 'BEGIN{RS="";FS="\n"}
{t=$NF}
match(t,/^"([^"]+)/,a){
key[NR]=tolower(a[1])"\t"++x
b[x]=$0
}
END {
asort(key)
for (i=1; i<=x; i++) {
split(key[i],a,"\t")
print b[a[2]] "\n"
}
}' file输出
/* The Hitchhiker's Guide to the Galaxy */
"42" = "the answer to life the universe and everything";
/* Optional field */
"Anny" = "Anny";
/* This is Billy */
"Billy" = "The smartest guy in the univererse";
"Johny" = "Johny";编辑
跳过前5行并仍打印它们
awk 'NR<6{print;next}
NR==6{RS="";FS="\n"}
{t=$NF}
match(t,/^"([^"]+)/,a){
key[NR]=tolower(a[1])"\t"++x
b[x]=$0
}
END {
asort(key)
for (i=1; i<=x; i++) {
split(key[i],a,"\t")
print b[a[2]] "\n"
}
}' file编辑2
我觉得这应该适用于Mac电脑
awk 'NR<6{print;next}
NR==6{RS="";FS="\n"}
{t=$NF}
split(t,a,"\""){
key[NR]=tolower(a[2])"\t"++x
b[x]=$0
}
END {
asort(key)
for (i=1; i<=x; i++) {
split(key[i],a,"\t")
print b[a[2]] "\n"
}
}' file发布于 2014-11-28 14:26:56
这是另一种方法。
X=5; file=<file>; \
head -n $X $file && \
cat $file | sed '1,'$X'd' | \
sed 's/\([^;]\)$/\1@@@/g' | \
tr -d '\n' | \
tr ';' '\n' | \
sed 's/$/;/g' | \
awk -F "@@@" '{print $2"@@@"$1}' | \
sed 's/^@@@//g' | \
sort --ignore-case | \
awk -F "@@@" '{print $2"\n"$1"\n"}' | \
cat -s解释一下。
X=5; file=<file>; \ # define variables
head -n $X $file && \ # output first set of lines
cat $file | sed '1,'$X'd' | \ # process rest of the lines
sed 's/\([^;]\)$/\1@@@/g' | \ # append @@@ to lines not ending with semicolon
tr -d '\n' | \ # remove all new lines and make a single line string
tr ';' '\n' | \ # break single string into multiple lines at semicolons
sed 's/$/;/g' | \ # add semicolons at the end of lines
awk -F "@@@" '{print $2"@@@"$1}' | \ # swap comment and translation
sed 's/^@@@//g' | \ # remove extra @@@ of translations without comments
sort --ignore-case | \ # sort
awk -F "@@@" '{print $2"\n"$1"\n"}' | \ # swap translation and comment, print with new lines
cat -s # remove extra new lineshttps://stackoverflow.com/questions/27186763
复制相似问题