Article View: pl.comp.lang.perl
Article #51989Re: podmiana wyrazenia w 1 pliku z 2
From: Szymon Sokół
Date: Thu, 23 Sep 2010 13:34
Date: Thu, 23 Sep 2010 13:34
38 lines
2836 bytes
2836 bytes
On Thu, 23 Sep 2010 09:23:43 +0200, Maciej Misiak wrote:
> Swoją drogą człowiek się całe życie uczy...
> Spodziewałem się, że i takie coś zadziała:
>
> C:\scripts>perl -p0e "s/(.*)ip=DANE/ip=$1/" plik-NUMER1 plik-NUMER2
>
> a tu lipa.
> Więc żeby skorzystać z "dodatkowego" feature, że p0 wciąga po jednym pliku do $_:
Może pod Windows. W moim unixowym manualu jest napisane:
-0[octal/hexadecimal]
specifies the input record separator ($/) as an octal or hexadecimal number. If there are no digits, the
null character is the separator. Other switches may precede or follow the digits. For example, if you
have a version of find which can print filenames terminated by the null character, you can say this:
find . -name ’*.orig’ -print0 | perl -n0e unlink
The special value 00 will cause Perl to slurp files in paragraph mode. The value 0777 will cause Perl to
slurp files whole because there is no legal byte with that value.
czyli -0 nie wciągnie całego pliku, jeśli ten zawiera NUL, -0777 wciągnie.
> C:\scripts>perl -p0e "s/DANE/$ip/||s/.*//;$ip=$&" plik-NUMER1 plik-NUMER2
...albo:
$ cat plik-NUMER1 plik-NUMER2 | perl -0777 -pe 's/(.*?)\nip=DANE/ip=$1/'
i zadziała (oczywiście zakładając, że pliki mają format dokładnie taki jak
w oryginalnym pytaniu) :-)
--
Szymon Sokół (SS316-RIPE) -- Network Manager B
Computer Center, AGH - University of Science and Technology, Cracow, Poland O
http://home.agh.edu.pl/szymon/ PGP key id: RSA: 0x2ABE016B, DSS: 0xF9289982 F
Free speech includes the right not to listen, if not interested -- Heinlein H
Technical Details
Message-ID:
<vgkxao6hs9nc.dlg@falcon.sloth.hell.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!dustpuppy.sloth.hell.pl!not-for-mailReferences:
<7d75.00000530.4c99e6b2@newsgate.onet.pl> <7d75.0000058f.4c9b007f@newsgate.onet.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!dustpuppy.sloth.hell.pl!not-for-mail
From: Szymon Sokół
<szymon@bastard.operator.from.hell.pl>
Newsgroups: pl.comp.lang.perl
Subject: Re: podmiana wyrazenia w 1 pliku z 2
Date: Thu, 23 Sep 2010 15:34:18 +0200
Organization: Guy Fawkes Society
Lines: 38
Sender: szymon@news.agh.edu.pl
Message-ID: <vgkxao6hs9nc.dlg@falcon.sloth.hell.pl>
References: <7d75.00000530.4c99e6b2@newsgate.onet.pl> <7d75.0000058f.4c9b007f@newsgate.onet.pl>
NNTP-Posting-Host: chello089078159131.chello.pl
Mime-Version: 1.0
X-Trace: news.agh.edu.pl 1285248920 10592 89.78.159.131 (23 Sep 2010 13:35:20 GMT)
X-Complaints-To: abuse@agh.edu.pl
NNTP-Posting-Date: Thu, 23 Sep 2010 13:35:20 +0000 (UTC)
User-Agent: 40tude_Dialog/2.0.15.1 Hamster/2.1.0.11
X-Face: xic?6f"rD)k-tM.]L]A6l4W7_aGt({}&{D,hiRI.8cPtf,1F.w@Qkl!vr23o1UY-BfXO$p< hk5>ijB?eBy)?!C<@)+%U\&`1X)MJ>.i.qgkY]4mvL62j<|xJRG/5:7:l8q]x;v!)Bz^r/!yG8DxoD -@fnC,g]BAXj
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit