Wednesday, January 25, 2012

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... :)

No comments:

Post a Comment