Using cat and awk.......

Im trying to use cat and awk to calculate the total space, then display it using the print command. But something in my script is not correct?

 cat | awk '{print$1}' | sort -n | grep -v used | awk '{sum += $1} END { p
rint sum;}'

??? Any help would be greatly appreciated!!

And what exactly are you trying to con-cat-enate?

cat "nothing" | to awk.....

dammit beat me to it by 3 seconds...!

lol~sorry guys. Do I have to use awk in shell scripting? Im new to scripting and I think that awk is confusisne me. I think I should stick to the basics first,

Im trying to display the output of the bdf command for filesystems, but I want to display total useage used, and total usage available.

Thanks in advance!
Bigben

using shell (bash)
example only.

df -HP | { while read disk b c d used e
do    
        used=${used%?}
        case  "$used" in
        [5-9][0-9])
            echo "overload over 50%: $disk, used: $used%"
        esac
done 
}

Imtrying to read the information, the use the bdf command to list the space used (etc). After that Im trying to get the info to display on the screen.

Below is what Ive been playing around with. While using the while do loop, do you have to use the output redirection?

while read list
do
        bdf $list
done <junk.txt | cat junk.txt | awk '{print$1}' | sort -n | grep -v used | awk '
{sum += $1} END { print sum;}'

---------- Post updated at 09:12 PM ---------- Previous update was at 09:07 PM ----------

I keep getting the error message:

cat: Cannot open junk.txt: No such file or directory,

I thought by using the awk/cat command it would create this file?

Bigben

Sorry If Im bothering anyone-just trying to learn.

if you are trying to create junk.txt , and assuming it hasn't been created yet, then why are you reading it using the while loop first?? do it this way

bdf <options> | while read ....
do
    # do your stuff
done

Would it know to bdf certain files?

 

find / -name filename 2>/dev/null
while read line
do
        bdf $line
done
 awk '{print$1}' | sort -n | grep -v used | awk '{sum += $1} END { print sum;}'

seriously, i have problem understanding your problem

Im sorry if Ive confused you...

Objective:

  1. Calculate the sum of total space, used space for all matching 'filesystems'
  2. Display "Total Space = xx " ; "Used Space = yy"; "Free space = zz"

This is the script I have wrote for it:

[code1]
find / -name 'filesystem' 2>/dev/null
while read line
do
bdf $line
done

awk '{print$1}' | sort -n | grep -v used | awk '{sum += $1} END { print sum;}'

The find command works fine, but the while do command hangs? So I dont know if the awk print line works?

Bigben

EDIT: woops didn't see there was page2