Friday, September 26, 2014

Useful *nix commands



to update

dbo.Transaction
truncate table dbo.Approval;
dbo.NextTable


to

truncate table dbo.Transaction;
truncate table dbo.Approval;
truncate table dbo.NextTable;


use this in Bash, both lines add text in the appropriate places if not already present

sed -e :a -e '/;$/!s/$/;/' file-list.sql > new-file-list.sql
sed -e :a -e '/truncate table /!s/^/truncate table /' new-file-list.sql > new2-file-list.sql

Show non ascii characters

nonascii() { LANG=C grep --color=always '[^ -~]\+'; }

printf 'ŨTF8\n' | nonascii


To remove line feeds, quotes and substitute quotes for a unique string. Used to format a field containing email content from a MySQL query extracted using concat('#K#',k.a_subject,'#K#') a

cat k2.sql | sed -e 's|["'\'']||g; s/`//g; s/#K#/\x27/g; s/\\n//g' > out.sql

Check for 8 digit numbers

grep -v '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' source.csv > without_8_digits.csv

grep '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' source.csv > with_8.csv

Extract lines in .csv with occurrences of the strings in .txt

grep -F -f client_people.txt source.csv > client_people_source.csv

sed-oneliners.