wiki:Scripting

Scripting (unix etc)

SQL=$(cat << EOD
    select *
    from foo
    where dork>2
EOD
)
echo $SQL   # BAD, eats newlines
echo "$SQL" # Good, keeps whitespace

Some non-greedy sed

Must be done by "not" matching

sed 's|\(http://[^/]*/\).*|\1|g'

echo a tab

Must have the -e switch

echo -e "foo\tbar"

awk find a row, give me a column

awk '/cpu family/{print $4}' /etc/cpuinfo

find's printf is probably new, can chmod a whole tree like a source tree

find /source -type f -printf "echo chmod %m %p\0" | xargs -0