Using sed for word count

Not sure how much use this is but using sed to count number of strings in a file e.g. how many times does Python appear in test.txt

[oracle@usnyssmtaora03 ~]$ cat test.txt
1
2
Python
this is a test
34
9
Perl
Python
Python
Python
Python
Python
Python
Python

[oracle@usnyssmtaora03 ~]$ sed -n 's/Python/&/gp' test.txt |sed 's/Python/&\n/g'|sed '/^ *$/d'|sed -n '$='
8


Search for cubica in a file i.e. string /u01/cubica - replace the string with cubicb and keep a previous copy of the file.

#!/bin/sh

for f in `find . -name '*.txt' -exec grep -il 'cubica' {} \;`
do
sed 's?cubica?cubicb?g' $f > ${f}.new
cp -p $f ${f}.prev
mv ${f}.new $f
done



MySQL dump / restore (quick notes)

Some quick notes on dump / restore of a MySQL database.

REM DUMP A DATABASE TO FILE NOTE: the -- database option will include the CREATE DATABASE IF NOT EXISTS AND USE DATABASE COMMANDS

mysqldump --host localhost -P 3306 -u root -p --databases INFO_DB > /u99/backup/INFO_DB_new.dmp

REM DUMP A DATABASE TO FILE NOTE: the this version will NOT include the CREATE DATABASE IF NOT EXISTS AND USE DATABASE COMMANDS

mysqldump --host localhost -P 3306 -u root -p INFO_DB > /u99/backup/INFO_DB_new.dmp

REM DUMP A DATABASE TO FILE (zipped)

mysqldump --host localhost -P 3306 -u root -p --databases INFO_DB | gzip > /u99/backup/INFO_DB_new.dmp.gz

REM RESTORE A FILE

mysql --host localhost -P 3306 -u root -p < /u99/backup/INFO_DB_new.dmp

REM RESTORE A DATABASE INTO AN EXISTING DATABASE "my_dbase"

mysql --host localhost -P 3306 -u root -p my_dbase< /u99/backup/INFO_DB_new.dmp

REM RESTORE A COMPRESSED DATABASE INTO AN EXISTING DATABASE "my_dbase"

gunzip < myfile.sql.gz | mysql -u root -p my_dbase

Chuckle Bros

I just want to say how sad it was to read about Barry Chuckle passing away. Great entertainer and a big miss. Him and his brother Paul have entertained for many years using good old fashioned humor and will be a big miss. If you have not watched the Chuckle Bros, loads on YouTube and I can thoroughly recommend giving them a go. Anyway, I was thinking that a Chuckle Bros Unix fortune command would be great so if anyone knows any sites with Chuckle Bros quotes please let me know.

Chuckle Bros.   "Nice church Vicar"
Vicar                 "It's Norman"
Chuckle Bros.   "Nice church Norman"

to you, to.........