Wednesday, May 02, 2007

Substitue

# substitute word
perl -e 's/gopher/World Wide Web/gi' -p -i.bak *.html

# Renaming within the name:
ls -1 *old* | awk '{print "mv "$1" "$1}' | sed s/old/new/2 | sh
(although in some cases it will fail, as in file_old_and_old)

OR

for i in *.sh
> do
> y=`echo $i |sed -e 's/hr/hd/'`
> mv $i $y
> done

# Execute as shell script and redirect log file
echo “restore.sh >restore.log 2>&1”|at now

# convert to upper case
cat fileName.txt | tr '[a-z]' '[A-Z]' > newFileName.txt
perl -p -e 'tr/t/p/;' -p -i fileName.txt
perl -p -e 'tr/a-z/A-Z/;' -p -i fileName.txt

-p option tells it to read and process each line from standard input and print the results to standard output
-e option lets you specify a Perl expression (a program, actually) on the command line.