Vi riporto un utilissimo comando Perl per effettuare ricerca + sostituzione nel contenuto di molteplici files. L'ho trovato in "Linux Journal" di marzo.
Bye, Paolo.
-------------------------------------------------------- Bulk Search -----------
Need to do a bulk search and replace on a whole bunch of files?
$ perl -pi -e 's/foo/bar/g;' filenames*
-e means execute the following Perl command (a normal search and replace).
-p means execute it for every input file, line by line, printing the result for each line in order.
-i means operate "in place": put the input in the same files as the original. If -i is followed immediately by a string, backup files will be created using that string as suffix. -----------------------------------------------------------------
Figata lo provato e funzio, ovviamente mi son dovuto prima cercare un perl tutorial per capire come funzionano le regular expressions in perl :)
Per chi come me ha di questi problemi ecco un link: http://www.comp.leeds.ac.uk/Perl/sandtr.html
Per chi è interessato a dei alias che mi son fatto in bash:
---------------------------- tmp$ alias ms alias ms='find . -name "*" -print | xargs grep -n '
ms sta per multiple search e cerca in tutti i files una parola esempio faccio ms 'Ciao bella' e mi fa unoutput contenente tutti i file contenenti la frase e anche la righe sulla quale è stata trovata, i.e. tmp$ ms 'Patrick Ohnewein' ./CachedRecordSet.java.back:5:// Programmierer: Patrick Ohnewein ./CachedRecordSet.java.back:16: * @author Patrick Ohnewein
---------------------------- tmp$ alias jms alias jms='find . -name "*.java" -print | xargs grep -n '
jms sta per java multiple search ed è una variante che cerca solo i files .java
---------------------------- tmp$ perl -pi.back -e 's/Patrick Ohnewein/pazzo/g;' *.java
questo è il commando perl che ho usato, ed ho sostituito tutti i 'Patrick Ohnewein' con 'pazzo' il g sta per Global e si potrebbe usare anche gi = global ignore case
ho anche cambiato -pi cioè -i in -i.back, cosi mi fa un backup file col suffix .back dei files che il serahcAndReplace cambia.
cu pazzo
dongilli@dnet.it wrote:
Vi riporto un utilissimo comando Perl per effettuare ricerca + sostituzione nel contenuto di molteplici files. L'ho trovato in "Linux Journal" di marzo.
Bye, Paolo.
Bulk Search
Need to do a bulk search and replace on a whole bunch of files?
$ perl -pi -e 's/foo/bar/g;' filenames*
-e means execute the following Perl command (a normal search and replace).
-p means execute it for every input file, line by line, printing the result for each line in order.
-i means operate "in place": put the input in the same files as the original. If -i is followed immediately by a string, backup files will be created using that string as suffix.
Lugbz-list mailing list Lugbz-list@lugbz.org https://secure.pcnotruf.net/mailman/listinfo/lugbz-list LUG-BZ is pcn.it-powered
To: lugbz-list@lugbz.org