I wanted to share with you a shell accomplishment I had today. For as long as
I've worked with unix, I've wanted to combine streams on the command line. I
just figured out how to do it tonight. Here I'm comparing 5 password files for
those usernames that are not in all of them:
# (cut -f 1 -d : passwd1 ; cut -f 1 -d : passwd2 >&2;
cut -f 1 -d : passwd3 >&3; cut -f 1 -d : passwd4 >&4 ;
cut -f 1 -d : passwd5 >&5) 2>&1 3>&1 4>&1 5>&1 |sort|uniq -c|grep -v 5
Output looks like this:
4 cory
3 jim
1 mike
10 sammy
That last one was amusing. Apparently "sammy" was in each file twice! Here's
a break down if you need it:
- cut -f 1 -d : <file>, means print the first column, delimited by :
- Each cut command goes into a stream: >&2, >&3, etc. The first one goes into
>&1 by default.
- All extra streams are redirected into the main stream: 2>&1 3>&1...
- All 5 combined streams are sorted
- Then sent through uniq -c which counts the number of occurances of each name
- grep -v 5 means print all rows that don't have the string '5'
I realize I could have also done this:
# cut -f 1 -d : passwd? |sort|uniq -c|grep -v 5
However the point of the exercise was combining streams from any programatic
source, not just cut.
Cory
--
Cory Petkovsek Adapting Information
Adaptable IT Consulting Technology to Your
(858) 705-1655 Business
[EMAIL PROTECTED] www.AdaptableIT.com
_______________________________________________
EuG-LUG mailing list
[EMAIL PROTECTED]
http://mailman.efn.org/cgi-bin/listinfo/eug-lug