Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2001
    Messaggi
    7,691

    ricerca e sostituzione nei file

    ciao,

    qualcuno conosce un prog. per linux (od anche uno script) che apra via via tutti i files di una dir, ricercando in ognuno di essi una data stringa e soatituendola con un'altra ed infine salvandoli ?

    Ho un centinaio di files da modificare e non ho voglia di passarci una giornata ...

    grazie

  2. #2
    Utente di HTML.it L'avatar di Guglie
    Registrato dal
    Dec 2002
    Messaggi
    1,572
    codice:
    #!/bin/bash
    
    function whelp()
    {
    	echo
    	echo "   USE: sedfunc [list=1] <newstring> <extension>"
    	echo
    	echo "   the script replaces in all the files with the"
    	echo "   <extension> extension [list=1] with <newstring>"
    	echo
    	echo "   if <extension> is not specified the program will"
    	echo "   replace the string in all the files in the directory"
    	echo
    	echo "   other options:"
    	echo "   -h, --help   display this help and exit"	
    	exit 0
    }
    
    if [ ! "$1" ] || [ ! "$2" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
    	whelp
    else
    	echo
    	echo "replacing ..."
    	
    	if [ "$3" ]; then
    		ext="*."$3
    	else
    		ext="*"
    	fi
    	
    	for f in `ls $ext`
    	do
    		sed -e 's/'$1'/'$2'/g' $f > $f.new
    	done
    	
    	for f in `ls *.new`
    	do
    	    mv $f `basename $f .new`
    	done
    fi
    
    exit 0
    semmai modificalo un po'

    ah, lo vedo adesso, se lo vuoi fare ricorsivo usa
    find -name $ext
    invece di
    ls $ext

    powered by GNU/Linux Gentoo
    A Elbereth Gilthoniel o menel palan-diriel, le nallon sí di-nguruthos! A tiro nin, Fanuilos!

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2001
    Messaggi
    7,691
    grazie, appena ho tempo, ci provo

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.