[lug] Some help with bash, please

Jeffrey Haemer jeffrey.haemer at gmail.com
Wed Feb 20 09:38:58 MST 2008


Ken,

You're just trying to be too clever.  Here's an easier way, done by, "recall
the line and add something."  Programming by accretion. :-)

*$ cat /tmp/foo*
fstab
passwd
group
*$ for i in $(< /tmp/foo); do echo /etc/$i; done   # Want to ensure they
exist? s/echo/ls/*
/etc/fstab
/etc/passwd
/etc/group
*$ wc -l $(for i in $(< /tmp/foo); do echo /etc/$i; done)*
  39 /etc/fstab
  81 /etc/group
  54 /etc/passwd
 174 total
*$ wc -l $(for i in $(< /tmp/foo); do echo /etc/$i; done) | perl -lane
'print if s/ total//'*
 174
*$ total=$(wc -l $(for i in $(< /tmp/foo); do echo /etc/$i; done) | perl
-lane 'print if s/ total//')
$ echo $total
* 174

Have another cup of coffee.  I'm going to. :-)

On Wed, Feb 20, 2008 at 9:17 AM, Kenneth D Weinert <kenw at quarter-flash.com>
wrote:

> OK, I'm feeling really dumb right now as this just isn't working for me.
> Here's the script I'm running:
>
> #!/bin/bash
>
> declare -xi total=0
> declare -xi count
>
> cat /tmp/orders | while read file;do
>        wc -l /dgorder/$file;
> done | while read count file;do
>        total=$((total + count))
> done
>
> echo "Number of Orders: $(wc -l /tmp/orders | tr -s ' '|cut -d' ' -f2)"
> echo "Total Documents:  $total"
>
> /tmp/orders is a file that has a filename, one per line
>
> Each /dgorder/$file has a number of records in it and I'm trying to
> count the total number of records in all the files.
>
> I think the double loop is what's killing me as the $total variable
> *always* ends up being zero.
>
> Any thoughts, hints, pointers, other scripting languages are more than
> welcome.  Since all the files are in the same directory I can fix the
> main input file to have complete paths instead of just file names if
> that helps.
>
> Thanks - and I'm sure that as soon as I see a response or two I'll do
> the old V8 slap to the forehead and wonder how I could be so dumb.
>
> --
> Ken Weinert
> http://quarter-flash.com
>
> Please avoid sending me Word or PowerPoint attachments
> http://www.gnu.org/philosophy/no-word-attachments.html
>
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
>



-- 
Jeffrey Haemer <jeffrey.haemer at gmail.com>
720-837-8908 [cell]
http://goyishekop.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20080220/82119046/attachment.html>


More information about the LUG mailing list