LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 04-28-2012, 08:57 AM   #1
UnixNewbie91
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Rep: Reputation: Disabled
Sorting GREP output


Hi

Have these two grep commands

for file in ~/webhits/*; do echo "$file: "$(grep $MONTH "$file" | grep -c $YEAR); done

for file in ~/webhits/*; do echo "$file: "$(grep $MONTH "$file" | grep $YEAR|cut -d" " -f 1,7|sort -u |wc -l); done

that produce outputs that look like:
/home/luke/webhits/bluray.hits: 8
/home/luke/webhits/books.hits: 7
/home/luke/webhits/cds.hits: 6
/home/luke/webhits/computing.hits: 7
/home/luke/webhits/dvds.hits: 7
/home/luke/webhits/gadgets.hits: 3
/home/luke/webhits/games.hits: 8
/home/luke/webhits/garden.hits: 5
/home/luke/webhits/home.hits: 3
/home/luke/webhits/index.hits: 24
/home/luke/webhits/jewellery.hits: 5
/home/luke/webhits/kitchen.hits: 4
/home/luke/webhits/posters.hits: 4
/home/luke/webhits/shoes.hits: 4
/home/luke/webhits/watches.hits: 4

Just wondering how to sort them by numeric order

Thanks in advance
 
Old 04-28-2012, 11:01 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
Run the output through sort -n.

Edit: you probably need to sort by the number field only, so use "sort -n -k2" instead.

Last edited by David the H.; 04-28-2012 at 11:14 AM. Reason: corrected suggestion.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Sorting output of du. stf92 Linux - Newbie 5 03-30-2010 07:37 AM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 11:31 PM
ps -eH | grep java output in a active passive clustered output johnkalikavunkal Linux - Server 2 01-31-2009 12:21 AM
Sorting recursive 'ls' and 'grep' SirTristan Linux - Newbie 5 03-13-2008 03:39 PM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 05:56 AM


All times are GMT -5. The time now is 11:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration