LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help with list filename with total size and divide by 555555 (https://www.linuxquestions.org/questions/linux-newbie-8/help-with-list-filename-with-total-size-and-divide-by-555555-a-4175493003/)

dotran 01-29-2014 11:56 AM

Help with list filename with total size and divide by 555555
 
Is the way can run one command line get total size and divide by 555555. Thanks

/export/home/mytmp/test1> ls -ltr testing*
-rw-r--r-- 1 ca7prod ftpusers 1179207454 Jan 24 10:18 testing_sftp1_MKT60000_20140108211807_F001.gz
-rw-r--r-- 1 ca7prod ftpusers 1179207454 Jan 27 11:00 testing_sftp2_MKT60000_20140108211807_F001.gz
-rw-r--r-- 1 ca7prod ftpusers 1179207454 Jan 27 11:12 testing_direc1_F001.gz
-rw-r--r-- 1 ca7prod ftpusers 1179207454 Jan 27 11:18 testing_direc2_F001.gz
/export/home/mytmp/test1> find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}'
4716829816
I try many way but not work.
/export/home/mytmp/test1> find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}' /555555 |bc

I like get output:
/export/home/mytmp/test1> echo 4716829816/555555 |bc
8490

Habitual 01-29-2014 12:26 PM

If
Code:

find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}'
spits out 4716829816

Why not try this,
Code:

MyVar=$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}')
echo (( $MyVar/555555 ))

spits out 8490 here also.

so, to use it at-will, use MyVar in a function:
Code:

GetFilesSizes {
MyVar=$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total})
}

NOTE: I suspect this may have to be an
Code:

export MyVar=$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total})
but I'm not certain of that.

then
Code:

echo (( $MyVar/555555 ))
To call it inside a script...
Code:

#!/bin/bash
do stuff
GetFilesSizes
echo (( $MyVar/555555 ))
do more stuff
...
#EOF

Smarter folks than I will have (no doubt) a better method of achieving the same result.

dotran 01-29-2014 12:37 PM

No...that' second command line. I want run one command line list filename get total sizie and divide by 5555 and output (xxxx)

This command already work just need add divide by 55555 and I can't make it work.
find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}'

Habitual 01-29-2014 12:41 PM

Quote:

Originally Posted by dotran (Post 5107589)
No...that' second command line. I want run one command line list filename get total sizie and divide by 5555 and output (xxxx)

This command already work just need add divide by 55555 and I can't make it work.
find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}'

try
Code:

$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}') / 55555 | bc
Please use [code][/code] tags. See my signature for the 411 on how to do that. - Thanks.

colucix 01-29-2014 12:52 PM

You can also reduce the output of find using -printf and do the calculation with awk:
Code:

find /export/home/mytmp/test1 -name testing\* -printf "%s\n" | awk '{sum+=$1} END{printf "%d\n", sum/55555}'

dotran 01-29-2014 01:16 PM

somehow still can't make it work.
#!/bin/ksh
MyVar=$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total
| awk '{total += $5};END {print total}') /555555 |bc >> count.txt

/export/home/mytmp/test1> ./dd.ksh
./dd.ksh[2]: /555555: not found

dotran 01-29-2014 02:47 PM

Somehow still can't this code work. Anyone have different syntax? The red part is work. Please help. Thanks

#!/bin/ksh -x
MyVar=`find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total |
awk '{total += $5};END {print total}'`
| echo (( $MyVar/555555 ))

/export/home/mytmp/test1> ./dd.ksh
./dd.ksh[2]: syntax error at line 2 : `((' unexpected

colucix 01-29-2014 02:57 PM

In your command (post #6) the string /555555 is interpreted literally, since the / sign is not inside an arithmetical operator. Moreover you're trying to assign the output of the command to a variable and redirect the output to a file simultaneously. It doesn't make sense.

Take a look at these variants:
Code:

echo $(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}') / 555555 | bc >> count.txt
Code:

MyVar=$(echo $(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}') / 555555 | bc)
Code:

MyVar=$(( $(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}') / 555555 ))
or look at my previous post for a shorter solution.

dotran 01-29-2014 03:16 PM

Thanks Mr Colucix. It's worked.


All times are GMT -5. The time now is 04:32 PM.