help rewrite files

help rewrite files

am 21.08.2009 17:04:00 von zilore mumba

--===============1651437771==
Content-Type: multipart/alternative; boundary="0-53834415-1250867040=:93986"

--0-53834415-1250867040=:93986
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Further to my earlier mail, this is how I have constructed my search/replac=
e patterns
       
s/nxny d{4} 5041/nxny 5041/g;    =A0 # nxny followed by 4 digits t=
hen 5041 replace by nxny 5041
s/(nx d{4}|ny 1)/nx 71|ny 71/g;     # nx followed by 4 digits & ny =
1 replace by nx 71 ny 71
s/(d{4} x 1)/(71 x 71)/g;              =A0 # (4=
digits x 1)=A0 in brackets replace by (71 x 71)
I wonder if the search/replace syntax is correct
Thanks for help
Zilore
=0A
--0-53834415-1250867040=:93986
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

<=
/table>

--0-53834415-1250867040=:93986--


--===============1651437771==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1651437771==--

RE: help rewrite files

am 21.08.2009 18:02:24 von Curtis Leach

This is a multi-part message in MIME format.

--===============0873861314==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01CA2278.D1852416"

This is a multi-part message in MIME format.

------_=_NextPart_001_01CA2278.D1852416
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: quoted-printable

Not quite right, parenthesis have special meaning in Perl regular
expressions. Also \d{4} means any 4 digits while d{4} means dddd. And
the "|" has no special meaning in the substitution part of the
expression The Learning Perl book has great chapters on this. It's
also a great reference for those new to Perl.
=20
So here's how all your examples could have been written.
s/nxny \d{4} 5041/nxny 5041/g; # nxny followed by 4 digits then 5041
replace by nxny 5041
s/nx \d{4}/nx 71/g; # nx followed by 4 digits
replace by nx 71
s/ny 1/ny 71/g; # ny 1 replace by nx 71
ny 71
s/\(\d{4} x 1\)/(71 x 71)/g; # (4 digits x 1) in brackets
replace by (71 x 71)

In the future, you might want to give an example source text with
expected results to make it clearer what you are trying to do. All the
above regular expressions require each section to be separated by a
single space.
=20
Also the 3rd one may not be quite right either depending on your data.
Since it would replace "nxny 1234" with "nxny 71234"
This is what I mean about knowing your data.
=20
Curtis

________________________________

From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of zilore
mumba
Sent: Friday, August 21, 2009 10:04 AM
To: activeperl@listserv.activestate.com
Subject: help rewrite files


Further to my earlier mail, this is how I have constructed my
search/replace patterns
=20
s/nxny d{4} 5041/nxny 5041/g; # nxny followed by 4 digits then 5041
replace by nxny 5041
s/(nx d{4}|ny 1)/nx 71|ny 71/g; # nx followed by 4 digits & ny 1
replace by nx 71 ny 71
s/(d{4} x 1)/(71 x 71)/g; # (4 digits x 1) in brackets
replace by (71 x 71)
I wonder if the search/replace syntax is correct
Thanks for help
Zilore
=09


------_=_NextPart_001_01CA2278.D1852416
Content-Type: text/html;
charset=us-ascii
Content-Transfer-Encoding: quoted-printable



charset=3Dus-ascii">


size=3D2> class=3D282494015-21082009>Not quite right, parenthesis have special =
meaning in=20
Perl regular expressions.  Also \d{4} means any 4 digits while d{4} =
means=20
dddd.  And the "|" has no special meaning in the=20
substitution part of the expression  The Learning Perl book =
has great=20
chapters on this.  It's also a great reference for those new to=20
Perl.

size=3D2> class=3D282494015-21082009> 

size=3D2> class=3D282494015-21082009>So here's how all your examples could have =
been=20
written.

size=3D2> class=3D282494015-21082009> color=3D#000000=20
size=3D3>s/nxny \d{4} 5041/nxny 5041/g;     # nxny =
followed by=20
4 digits then 5041 replace by nxny 5041
s/nx \d{4}/nx=20
71/g;           &n=
bsp;          =20
  # nx followed by 4 digits  replace by nx 71
s/ny 1/ny=20
71/g;           &n=
bsp;           &nb=
sp;  =20
     # ny 1 replace by nx 71 ny 71
s/\(\d{4} x 1\)/(71 =
x=20
71)/g;           =
  =20
# (4 digits x 1)  in brackets replace by (71 x=20
71)


size=3D2> class=3D282494015-21082009>In the future, you might want to give an =
example source=20
text with expected results to make it clearer what you are trying to=20
do.  All the above regular expressions require each section to =
be=20
separated by a single space.

size=3D2> class=3D282494015-21082009> 

size=3D2> class=3D282494015-21082009>Also the 3rd one may not be quite right =
either=20
depending on your data.

size=3D2> class=3D282494015-21082009>Since it would replace "nxny 1234" with "nxny =

71234"

size=3D2> class=3D282494015-21082009>This is what I mean about knowing your=20
data.

size=3D2> class=3D282494015-21082009> 

size=3D2> class=3D282494015-21082009>Curtis





From:=20
activeperl-bounces@listserv.ActiveState.com=20
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of =
zilore=20
mumba
Sent: Friday, August 21, 2009 10:04 AM
To:=20
activeperl@listserv.activestate.com
Subject: help rewrite=20
files



top" style=3D"font: inherit;">Further to my earlier mail, this is how I hav=
e constructed my search/replace patterns
     &=
nbsp; 
s/nxny d{4} 5041/nxny 5041/g;     =
; # nxny followed by 4 digits then 5041 replace by nxny 5041
s/(nx d{4}|=
ny 1)/nx 71|ny 71/g;     # nx followed by 4 digits &=
; ny 1 replace by nx 71 ny 71
s/(d{4} x 1)/(71 x 71)/g;   =
;             #=
(4 digits x 1)  in brackets replace by (71 x 71)
I wonder if the s=
earch/replace syntax is correct
Thanks for help
Zilore



Further to my earlier mail, this is how I have =
constructed=20
my search/replace =
patterns
       =20

s/nxny d{4} 5041/nxny 5041/g;      # =
nxny=20
followed by 4 digits then 5041 replace by nxny 5041
s/(nx =
d{4}|ny 1)/nx=20
71|ny 71/g;     # nx followed by 4 digits =
& ny 1=20
replace by nx 71 ny 71
s/(d{4} x 1)/(71 x=20
=
71)/g;           &=
nbsp;   =20
# (4 digits x 1)  in brackets replace by (71 x 71)
I =
wonder if the=20
search/replace syntax is correct
Thanks for=20
help
Zilore



------_=_NextPart_001_01CA2278.D1852416--


--===============0873861314==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0873861314==--

RE: help rewrite files

am 21.08.2009 21:21:52 von zilore mumba

--===============0852669356==
Content-Type: multipart/alternative; boundary="0-564447578-1250882512=:87700"

--0-564447578-1250882512=:87700
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Thanks very much Curtis.
I will try your suggestions.
Meanwhile, below is some of the text that appears in my files. The text to =
be replaced is in blue. Somewhere in the file there is nxny 1369 1380. 1369=
is the correct one (37 x 37).

The people who are writing the files (these are forecast winds ...) are wri=
ting in complex format, hence the double headers and my software is not abl=
e to read correctly because of double headers.
Zilore

rec 1:0:date 2009072900 UGRD kpds5=3D33 kpds6=3D100 kpds7=3D850 levels=3D(3=
,82) grid=3D255 850 mb 24hr fcst:
=A0 UGRD=3Du wind [m/s]
=A0 timerange 0 P1 24 P2 0 TimeU 1=A0 nx 1380 ny 1 GDS grid 0 num_in_ave 0 =
missing 0
=A0 center 98 subcenter 0 process 110 Table 1
=A0 latlon: lat=A0 90.000000 to 0.000000 by 2.500000=A0 nxny 1380
        =A0 long -90.000000 to 0.000000 by 2.500000, (1380 =
x 1) scan 0 mode 128 bdsgrid 1
=A0 min/max data -21.0971 -5.09805=A0 num bits 14=A0 BDS_Ref -21.0971=A0 De=
cScale 0 BinScale -10





=0A
--0-564447578-1250882512=:87700
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

top" style=3D"font: inherit;">Thanks very much Curtis.
I will try your s=
uggestions.
Meanwhile, below is some of the text that appears in my file=
s. The text to be replaced is in blue. Somewhere in the file there is style=3D"color: rgb(0, 0, 255);">nxny 1369 1380. 1369 is the correc=
t one (37 x 37).

The people who are writing the files (these are for=
ecast winds ...) are writing in complex format, hence the double headers an=
d my software is not able to read correctly because of double headers.
Z=
ilore

rec 1:0:date 2009072900 UGRD kpds5=3D33 kpds6=3D100 kpds7=3D85=
0 levels=3D(3,82) grid=3D255 850 mb 24hr fcst:
  UGRD=3Du wind [m/s=
]
  timerange 0 P1 24 P2 0 TimeU 1  0, 0, 255);">nx 1380 ny 1 GDS grid 0 num_in_ave 0 missing 0
 =
; center 98 subcenter 0 process 110 Table 1
  latlon: lat  90.=
000000 to 0.000000
by 2.500000  nxny 1380<=
br>          long -90.000000 t=
o 0.000000 by 2.500000, (1380 x 1) span> scan 0 mode 128 bdsgrid 1
  min/max data -21.0971 -5.09805&nb=
sp; num bits 14  BDS_Ref -21.0971  DecScale 0 BinScale -10
>





--0-564447578-1250882512=:87700--


--===============0852669356==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0852669356==--

Re: help rewrite files

am 21.08.2009 22:57:20 von jwkenne

On Aug 21, 2009, at 3:21 PM, zilore mumba wrote:
> Thanks very much Curtis.
> I will try your suggestions.
> Meanwhile, below is some of the text that appears in my files. The
> text to be replaced is in blue. Somewhere in the file there is nxny
> 1369 1380. 1369 is the correct one (37 x 37).
>
> The people who are writing the files (these are forecast winds ...)
> are writing in complex format, hence the double headers and my
> software is not able to read correctly because of double headers.
> Zilore
>
> rec 1:0:date 2009072900 UGRD kpds5=33 kpds6=100 kpds7=850
> levels=(3,82) grid=255 850 mb 24hr fcst:
> UGRD=u wind [m/s]
> timerange 0 P1 24 P2 0 TimeU 1 nx 1380 ny 1 GDS grid 0 num_in_ave
> 0 missing 0
> center 98 subcenter 0 process 110 Table 1
> latlon: lat 90.000000 to 0.000000 by 2.500000 nxny 1380
> long -90.000000 to 0.000000 by 2.500000, (1380 x 1) scan 0
> mode 128 bdsgrid 1
> min/max data -21.0971 -5.09805 num bits 14 BDS_Ref -21.0971
> DecScale 0 BinScale -10

You /cannot/ do what you want to do. These are variable-length
records. You cannot rewrite them; you /must/ create a new file.

--
John W Kennedy
"Compact is becoming contract,
Man only earns and pays."
-- Charles Williams. "Bors to Elayne: On the King's Coins"




_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: help rewrite files

am 22.08.2009 00:08:00 von Bill Luebkert

John W Kennedy wrote:
>
> You /cannot/ do what you want to do. These are variable-length
> records. You cannot rewrite them; you /must/ create a new file.

Sure he can - if you noticed the code earlier, you would note
that he read the file in, modified and pushed each line into
an array and then rewound and wrote it back.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs