[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] how to translate one file

From: lina
Subject: Re: [Help-bash] how to translate one file
Date: Tue, 03 Jan 2012 23:32:12 +0800
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20111114 Icedove/3.1.16

On Tuesday 03,January,2012 11:23 PM, Greg Wooledge wrote:
On Tue, Jan 03, 2012 at 11:15:20PM +0800, lina wrote:
/* Generated by g_mmdat_g_f */
/* legend:  "Distance (nm)" */
/* x-label: "Residue Index" */
/* y-label: "Residue Index" */
static char *grmacos_xpm[] = {
"D  c #EBEBEB " /* "0.115" */,
"E  c #E5E5E5 " /* "0.154" */,
"F  c #DEDEDE " /* "0.192" */,
"G  c #D8D8D8 " /* "0.231" */,
And you can't use some existing XPM parsing program to do whatever it is
you're trying to do?

Oh, don't worry, actually this real problem has been solved by following script and another version written by python.

$ cat

for f in *.xpm

awk '{if(NF==7) print $1, $6}' $f | tr -d '"' | sed 's/[a-Z]/s\/&\//g' | tr -d ' ' | sed 's/^.*$/& \/g/g' > dict.txt

tail -1 $f | tr -d '"' > lastline.txt

sed -f dict.txt lastline.txt | sed 's/.\(.*\)/\1/' | sed -e 's/[ ]*//' | sort -n -k2 -n -k3 -n -k4 -n -k5 -n -k6 -n -k7 -n -k8 -n -k9 -n -k10 -n -k11 -n -k12 -n -k13 -n -k14 -n -k15 -n -k16 -n -k17 -n -k18 -n -k19 -n -k20 -n -k21 -n -k22 -n -k23 -n -k24 -n -k25 -n -k26 -n -k27 -n -k28 -n -k29 -n -k30 -n -k31 -n -k32 -n -k33 -n -k34 -n -k35 -n -k36 -n -k37 -n -k38 -n -k39 -n -k40 -n -k41 -n -k42 | sed 's/[ ]*//' >> a.out


I have problem in dropping the first 5 lines. I wish to start with the
parts include key and value.
If you know in advance that it's 5 lines, then:

while IFS='" ' read _ letter _ color _; do
done<  <(sed 1,5d foobar.xpm)

Or if you want to be a bit less rigid, then:

while IFS='" ' read _ letter _ color _; do
done<  <(grep '^"' foobar.xpm)

Though I'd still look for existing XPM tools.
Thanks for your time,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]