From: Jack Shown on 19 Dec 2009 22:32 On Dec 19, 1:46 am, mop2 <inva...(a)mail.address> wrote: > On Sat, 19 Dec 2009 05:36:42 -0200, Jack Shown <jacksh...(a)gmail.com> wrote: > > Hi Janis, I think that's exactly what I tried (as I mentioned in my > > previous post) but I gave yours a whirl anyway and it still did not > > substitute. I put what you wrote into a small shell script and ran it > > with bash -x to see it execute and the command output looks like I > > think it should: > > > + sed -e 's/ width="[0-9]\+"/ width="256"/' -e 's/ height="[0-9]\ > > +"/ height="192"/' > > > I appreciate your efforts. > > > Jack > > $ bash -version|head -n1;sed --version|head -n1 > GNU bash, version 4.0.35(1)-release (i686-pc-linux-gnu) > GNU sed version 4.2.1 > $ > > $ cat file > #------ > WIDTH=400 > HEIGHT=20 > > sed ' > s/ width="[0-9]\+"/ width="'$WIDTH'"/ > s/ height="[0-9]\+"/ height="'$HEIGHT'"/ > ' file > > return > > <zzzzz width="33" yyyyy height="555" wwwwww> > #---------------- > > $ . ./file > #------ > WIDTH=400 > HEIGHT=20 > > sed ' > s/ width="[0-9]\+"/ width="'$WIDTH'"/ > s/ height="[0-9]\+"/ height="'$HEIGHT'"/ > ' file > > return > > <zzzzz width="400" yyyyy height="20" wwwwww> > #---------------- > > $ It must be that my version of sed is just an old version because it doesn't permit the '--version' nor does the output from strings /usr/ bin/sed show any kind of version although I did find "2003" in the output. Thanks for trying to help. I really appreciate it.
From: Kevin Collins on 23 Dec 2009 14:11 On 2009-12-19, Jack Shown <jackshown(a)gmail.com> wrote: > 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. Of course the values in your input file remain unchanged - this is sed and it is redirecting output to a new file ("filename.new" in the code above). You can use perl with in-line editing to change the source file itself: perl -pi -e ' # adjust the aspecy by? $aspect = .5; # for height if (/\bheight="(\d+)"/) { $h = int($1 * $aspect); s/\bheight="$1"/height="$h"/; } # for height if (/\bwidth="(\d+)"/) { $w = int($1 * $aspect); s/\bwidth="$1"/width="$w"/; } ' your_file_name This should do what you want pretty handily, I think. If it were me, I would be tempted to make the matches case-insensitive (/.../i, s/.../.../i), since it appears to be HTML and the case could change. Kevin
First
|
Prev
|
Pages: 1 2 3 4 Prev: What does 'S' mean in mode? And how to remove it? Next: configure MySQL on Leopard |