Wednesday, December 14, 2011

Shell: convert UPPER case to lower case

Hate CAPITOL LETTERS!?  Yea, me too.  If some noob sends you an all capitol letter based server-name feel free to:

1) hit them
2) convert the letters to LOWER CASE.

echo $word| tr [:upper:] [:lower:]

This will use tr (translate) to move the characters from UPPER to lower case.

Monday, December 5, 2011

Get one word (or phrase) only from a set of text or file

So  you want to get some text from a file.  Easy, use grep.  What; you want more than that?  Oh, you want ONLY the word (or phrase) from that file, not the entire line!  Ahhh!

It took me a few tries, but I combined grep and sed to give me the line I wanted, then then only the word I wanted.

In this case I was searching spam emails I have gotten for the senders email address. 


grep -i "From: " *|  sed -e 's/^.*<\(.*\)>,*/\1/'

The line from the grep looks like:
3 0735.eml:From: "Fraud Prevention" <douchbag@spamsucks.com>

Then the sed line pulls out the email between the < >