grep ".mp3\|.mp4" $file | wc -l

.. Add whatever cases to the regex you're interested in.  And add more grep
runs for each type.  You'll have to get the total manually though.

Hth
On Sep 16, 2012 3:10 AM, "Michael Quick" <[email protected]> wrote:

> Hey bash coders,
> I have a list of certain file types in a file (i.e. /home/<userid>/music
> file.mp3 per line).  So I created a loop to step through the file and count
> them an old school way... this seemed the most reliable.  Anyone have a
> better way ?  Or this may help someone out if they ever need to do it.
> PS> I keep forgetting that it's currently 3AM in the US and only 3PM here
> in Singapore.. . lol
>
>
>     while read line; do
>
>         case ${line} in
>               # match end of string
>               *".mp3"|*".mp4"|*".m4a"|*".rm"|*".ogg"|*".aac") (( AUDIO +=
> 1 )) ;(( TOTAL += 1 )) ;;
>
>               *".wmv"|*".mov"|*".avi"|*".ogv") (( VIDEO += 1 )) ;(( TOTAL
> += 1 )) ;;
>
>               *".jpg") (( IMAGES += 1 )) ;(( TOTAL += 1 )) ;;
>         esac
>
>     done < ${FILTEREDMEDIA_LOWERCASE}
>
>
> #
> ------------------------------------------------------------------------------------------------#
> ## Personal Media Search Results
> #
> ------------------------------------------------------------------------------------------------#
>  Audio  : [ 198 ]
>  Video  : [ 35 ]
>  Images : [ 203 ]
> ----------------
>  Total  : [ 436 ]
> #
> ------------------------------------------------------------------------------------------------#
> /home/itsupport/walls/542404_4030094224742_1348100040_n.jpg
> /home/itsupport/walls/header.jpg
> /home/itsupport/pictures personal/club pics/127.jpg
> /home/itsupport/pictures personal/club pics/2012-06-28/084.jpg
> /home/itsupport/pictures personal/club pics/2012-06-28/070.jpg
> /home/itsupport/pictures personal/club pics/2012-06-28/019.jpg
> /home/itsupport/pictures personal/club pics/2012-06-28/041.jpg
> /home/itsupport/pictures personal/club pics/2012-06-28/035.jpg
> /home/itsupport/pictures personal/club pics/2012-06-28/030.jpg
> /home/itsupport/pictures personal/club pics/2012-06-28/033.jpg
> /home/itsupport/pictures personal/club pics/2012-06-28/040.jpg
> ........ . .....    ......
>
> _______________________________________________
> Mid-Hudson Valley Linux Users Group                  http://mhvlug.org
> http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug
>
> Upcoming Meetings (6pm - 8pm)                         Vassar College
>   Oct 3 - Mobile Web Development
>   Nov 7 - Typography: Physical Art to Digital Art
>   Dec 5 - Sysadmin Panel
>
>
_______________________________________________
Mid-Hudson Valley Linux Users Group                  http://mhvlug.org
http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug

Upcoming Meetings (6pm - 8pm)                         Vassar College
  Oct 3 - Mobile Web Development
  Nov 7 - Typography: Physical Art to Digital Art
  Dec 5 - Sysadmin Panel

Reply via email to