Unix beginner. Need some very basic help.

Hey all I'm working on a script that will scour a directory of 6000+ files for a line that at the end has a number.

Something like 'The number of outputs is: 39200'

I'm trying to devise a script to add all of these numbers up, so far I have the grep statement that pulls out each individual line but am clueless on how you go about taking certain parts of that line and storing/adding it somewhere else.

<your grep command> |
 awk '
          { total += $NF }
         END { print total }
        '

isn't $NF the number of fields per line? I ran this and got

7.67563e+10

how does one specify the last field of a line? If I could do that I think I would just have to substitute whatever variable that is in for the $NF

hm, I read a few of the files and since all the lines are the same I substituted $NF with $6 the field containing the number and get the same result? How can I display the full number, I know what it is just not how to display it.

Your syntax seems right -- I'd guess the problem is elsewhere.

Print each one as you go as well, just to make sure there isn't a really big number in there. If you have 6000 files it's quite feasible that you are looking at some files you shouldn't. So print the number and the file name for each and sort that list to see where the big one(s) are coming from.

Well it is a rather large number:8852934720

1317401 * 6720

is what it boils down to.

era: there's 6720 files in the directory, and every file has a number that i'm trying to pull, and each number is the same, the 1317401 when i put that into a regular calc i get the 8.8billion number, however the output i'm getting is the 7.67...e10 which is like 76 billion

edit: I ran my grep and piped it to a wc -l to ensure each file had this line in it, the result was the same number of files in the directory.

Do you get the same result as me on this?

vnix$ awk 'BEGIN { print 8852934720 }' </dev/null
8.85293e+09

If you get a much bigger number then this is likely a case of integer overflow in your awk.

So if you use grep to print the file name and the number from each file, and sort by the number, do you see any weird numbers which don't match your expectations?

NF is the number of fields in the current line.
$NF is the content of that field.

printf "%.0f\n", total