[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [linux-team] question sed
Tout à fait d'accord avec Alain pour le Perl, mais juste pour le fun...
voici la même chose avec awk:
cat brol \
| awk '/lalignearemplacer-cestuneregexp/ { print "blah\nblah2\nblah3\n"; next } { print $0 }'
voilou...
> #!/usr/bin/perl
> # ----------------------
> while (<>) {
> if ( /target/ ) {
> print "hhgfhg \n";
> print "hhgfhg \n";
> ...
> }
> else { print;
> }
> }
> # ----------------------
> C'est plus long, mais beaucoup plus souple et plus lisible.
Tu peux raccourcir:
cat brol \
| perl -ne 'if (/target/) { print "blahblah\nblahblah2\n"; } else { print $_; }'
-o) Pascal Bleser | UNIX *is* user friendly.
/\\ C++/UNIX Development | It's just selective about
_\_v ATOS Payment Systems | who its friends are...
pbleser@atos-group.com---------------------------------
---------
This message was sent by Majordomo 1.94.3. Please report problems to
manu@rtfm.be. If you want to be deleted from the list, send a mail to
majordomo@rtfm.be with "unsubscribe linux-team" in the body.