Wednesday, January 25, 2012

Command to see info on GPG key

Command to see info on GPG key
 rpm -q --qf "%{NAME}-%{VERSION}-%{RELEASE} \n %{SUMMARY} \n" gpg-pubkey


Operate on data input from the command line

So you want to quickly sort a list without going through a lot of steps.  This is what was happening to me, and I found a quick and easy way to do that from the command line.  This technique will work for any other operation that you want to preform as well.

Here is the command:
cat << EOF | sort [enter]
[enter text here]
EOF [enter]

The [enter text here] will then be output to the command line sorted.  You can get very fancy with this technique. This comes in handy when you have a set of text already stored in the copy buffer (clipboard).  Then you can just copy and paste into the [enter text here] section and very quickly have your desired operation.

Here is another example:
cat << EOF |sort > test [enter]
[enter text here]
EOF [enter]

This does the same thing, but puts the results into a file called 'test'.  Obviously you can get very creative with this.  Then again, if you are going crazy with this a small shell script may be better.  Then again, small shell scripts can replace many of us... :)

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 < >

Thursday, October 27, 2011

Save a file edited in vim without the needed permissions

:w !sudo tee %

Have you ever been editing a file in vi or vim and found out that you cannot save it due to permissions?  Yea, me too.  Ugh!  The shortcut above utilizes your sudo permissions to hand off the write to tee so that it can be saved out of vi or vim.

Rejoice!  Of course this requires that you have at least sudo permissions to edit the file.  Sorry hackers!