Monday, April 27, 2009

ruby script to search for email addresses in a log file

Given input that is ":" delimited, this script will search out email addresses in any field in the input:


cat log_file.txt | ruby -ne 'split(":").each { |col| print col , "\n" if col.match(/^\S+@\S+$/) }' | sort | uniq

Wednesday, April 22, 2009

awk script to add up lines in a file

You want to add up the numbers in a file?

Input:

56168
796
44
26
202
258
478
632

Script:

cat file | awk '{ total = total + $1} END { print total}'