From: Jack Shown on
I have files that contain strings such as: width="???" height="???"
where the question marks represent positive integers of either two or
three digits. Similar strings do exist but only once in each file does
" width=" and " height=" exist. If I don't know where this string
exists for sure, is there anyway to obtain those values and replace
them based on their aspect ratio? I don't need the aspect ratio
conversion math, of course, just the extraction and the replacement.
I'm using bash but perl or python would work too of course. Thx.
From: Barry Margolin on
In article
<4f1bc9a0-41c6-44a2-bca3-5358b51af9ba(a)g1g2000pra.googlegroups.com>,
Jack Shown <jackshown(a)gmail.com> wrote:

> I have files that contain strings such as: width="???" height="???"
> where the question marks represent positive integers of either two or
> three digits. Similar strings do exist but only once in each file does
> " width=" and " height=" exist. If I don't know where this string
> exists for sure, is there anyway to obtain those values and replace
> them based on their aspect ratio? I don't need the aspect ratio
> conversion math, of course, just the extraction and the replacement.
> I'm using bash but perl or python would work too of course. Thx.

Does this do what you want:

WIDTH=80
HEIGHT=24
sed -e 's/width="\?+\"/width="'$WIDTH'"/' -e
's/height="\?+\"/height="'$HEIGHT'"/' filename > filename.new

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Jack Shown on
On Dec 18, 7:22 pm, Barry Margolin <bar...(a)alum.mit.edu> wrote:
> In article
> <4f1bc9a0-41c6-44a2-bca3-5358b51af...(a)g1g2000pra.googlegroups.com>,
>  Jack Shown <jacksh...(a)gmail.com> wrote:
>
> > I have files that contain strings such as:  width="???" height="???"
> > where the question marks represent positive integers of either two or
> > three digits. Similar strings do exist but only once in each file does
> > " width=" and " height=" exist. If I don't know where this string
> > exists for sure, is there anyway to obtain those values and replace
> > them based on their aspect ratio?  I don't need the aspect ratio
> > conversion math, of course, just the extraction and the replacement.
> > I'm using bash but perl or python would work too of course.  Thx.
>
> Does this do what you want:
>
> WIDTH=80
> HEIGHT=24
> sed -e 's/width="\?+\"/width="'$WIDTH'"/' -e
> 's/height="\?+\"/height="'$HEIGHT'"/' filename > filename.new
>
> --
> Barry Margolin, bar...(a)alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***

Hi Barry,

That looked very promising but, unfortunately, the values in the input
file remained unmodified.

Thx for your effort, Jack
From: Janis Papanagnou on
Jack Shown wrote:
> I have files that contain strings such as: width="???" height="???"
> where the question marks represent positive integers of either two or
> three digits. Similar strings do exist but only once in each file does
> " width=" and " height=" exist. If I don't know where this string
> exists for sure, is there anyway to obtain those values and replace
> them based on their aspect ratio? I don't need the aspect ratio
> conversion math, of course, just the extraction and the replacement.
> I'm using bash but perl or python would work too of course. Thx.

Based on Barry's solution path try...

sed -e "s/ width=[0-9]\+/ width=$WIDTH/" \
-e "s/ height=[0-9]\+/ height=$HEIGHT/" < infile > outfile

But your "based on their aspect ratio" sounds like you want some
calculations based on the previous values involved? If so, please
clarify your demands.

Janis
From: Jack Shown on
On Dec 18, 9:29 pm, Janis Papanagnou <janis_papanag...(a)hotmail.com>
wrote:
> Jack Shown wrote:
> > I have files that contain strings such as:  width="???" height="???"
> > where the question marks represent positive integers of either two or
> > three digits. Similar strings do exist but only once in each file does
> > " width=" and " height=" exist. If I don't know where this string
> > exists for sure, is there anyway to obtain those values and replace
> > them based on their aspect ratio?  I don't need the aspect ratio
> > conversion math, of course, just the extraction and the replacement.
> > I'm using bash but perl or python would work too of course.  Thx.
>
> Based on Barry's solution path try...
>
> sed -e "s/ width=[0-9]\+/ width=$WIDTH/" \
>      -e "s/ height=[0-9]\+/ height=$HEIGHT/"  < infile  > outfile
>
> But your "based on their aspect ratio" sounds like you want some
> calculations based on the previous values involved? If so, please
> clarify your demands.
>
> Janis

No, the aspect ratio does not affect the substitution as Barry rightly
chose numbers such as 80x24.

I think your attempt is almost there but it misses the quote (") on
each side of the integer value thus the substitution is not
performed. I tried it with \" on each side but didn't get a
substitution either.

The input is what one would obtain from Google Maps when, for example,
getting directions from one place to another. If you then click
"Link" in the top right corner, you obtain the code that is used to
reproduce a similar map on your site. It is that code that is my
input file. However, I cannot know what values someone may choose.
I think 425 and 350 are the default but can be overridden by
"Customize and preview embedded map" which you see below Google's
provided html.