Sunday, April 7, 2013

Beets and goat cheese arugula salad

Ingredients
Arugula 8 oz
Beets 1 medium
Goat cheeze 8 oz
Balsamic vinegar 
Extra virgin olive oil

Preparation 
 
Cook beets in microwave or boil on the stove unpeeled (same way you'll prepare a big potato -- just it will take 2.5 times longer).
Dress a generous pile of arugula salad with olive oil mixed with balsamic vinegar (hint: if you balsamic vinegar is cheap and watery, heat it and make it more condenced).
Top it with chunks of goat cheese and slices of peeled beets.

This salad is very elegant, pleasing for the eye and the palate. 
Enjoy!


Linux, bash tips

Capture output, linux, bash

# send standard output to file named out and error output to file named err
master.sh >out 2>err
# send all output to one file named allout
master.sh 2>&1>allout
equivalent to
master.sh &>allout

Copy shell script to another location from itself
cp $0 destination

Saturday, April 6, 2013

Linux scripts: we use grep, sed, awk, sort, uniq, pipe

Tab delimited file with 3d column consisting of comma-separated integers.
Goal: using bash script
pick all records matching pattern=PATTERN
count all occurrences of each integer in the file
sort desc by occurrences

Highlights:
>tr -s ',' '\n' ==or== sed 's/,/\n/g'
>sort -r -n -b ----- reverse, numeric, omit trailing blanks
>uniq  ------- for counting pre-sorted records
> | -------- piping output from one process into another (all interim files are not necessary, everything could be piped through!

#!/bin/bash
grep PATTERN | sed 's/\t*PATTERN\t*,/\t/g' > matching_records.csv
cat matching_records.csv | awk -F '\t' '{print $2}' > csv_column.csv
cat csv_column.csv | tr -s ',' '\n' | sort -n | uniq -c | sort -r -n -b

Linux / unix tips: paste

>paste [-s] [-d delim-list] [--serial] [--delimiters=delim-list] [--help] [--version] [file...]

http://linux.about.com/library/cmd/blcmdl_paste.htm
paste prints lines consisting of sequentially corresponding lines of each specified file. In the output the original lines are separated by TABs. The output line is terminated with a newline.

Example - convert tab-delimited file into csv:
http://askubuntu.com/questions/174008/write-bash-script-which-takes-input-from-pipe
cat some_list_of_elements.txt | awk '{print "\047"$1"\047"}' | paste -d, -s
It takes a list of items from a file, wraps each in quotes, and merges them together in a comma-separated list.

Thursday, April 4, 2013

Linux tips

Copy shell script from inside
cp $0 destination

Remove file with name starting with dash
rm -- -file-with-weird-prefix