Friday, October 31, 2014

Using Immediate documents (cat << EOF) to avoid shell quoting problems

If you want to add an entry to an alias file you normally have to jump through hoops to get the quoting properly, much easier with an immediate document since you can type the way would if editing the document itself:

cat <<EOF >> myaliases.bsh
alias go2usb='cd "/var/host/media/removable/USB Drive/"'

Thursday, October 30, 2014

Loop on tail -f for dynamic processing

Lets say you get some interesting files:

for a in {000001..249510}; do wget --random-wait -U "Mozilla/5.0 (Windows NT 5.1; rv:10.0.1)" "$a"; done

then you suspect you missed a few... 

You can open a terminal window (or background) this: 

for a in {000001..249510}; do ((! $(grep -c A$a files.txt))) && (echo $a >> missing_files.txt); done

... and since it will take a while in a new terminal you can "Loop on tail -f for dynamic processing"

tail -f missing_files.txt | while read a; do wget --random-wait -U "Mozilla/5.1 (Windows NT 5.0; rv:10.0.2)" "$a"; done