A Newbie AWK question 
Author Message
 A Newbie AWK question

Have a problem that Awk is sure to solve, but I have hit a brick wall
this this respect.

I have 5 files that in them contain the avaible space on disk sets.
these are avaiable amount , percentage used, and directory path.

The files are like this below

791032 79% /de/ingdp
1976610 86% /de/ingdp/data1
2131688 85% /de/ingdp/data2
2273315 84% /de/ingdp/data3
2011808 86% /de/ingdp/data4

What I wish to do is to extract each indivdual row, and move each
column into a designated varible so

Ava1=791032
per1=79
dir1=/de/ingdp

Ava2=1976610
per2=86
dir2=/de/ingdp/data1

....
...

This will allow me to then present this on the screen.

Any hints, clues please.

Thank you in Advance

Simon
So you get 5



Mon, 11 Jul 2005 22:40:40 GMT  
 A Newbie AWK question

Quote:
> Have a problem that Awk is sure to solve, but I have hit a brick wall
> this this respect.

> I have 5 files that in them contain the avaible space on disk sets.
> these are avaiable amount , percentage used, and directory path.

> The files are like this below

> 791032 79% /de/ingdp
> 1976610 86% /de/ingdp/data1
> 2131688 85% /de/ingdp/data2
> 2273315 84% /de/ingdp/data3
> 2011808 86% /de/ingdp/data4

> What I wish to do is to extract each indivdual row, and move each
> column into a designated varible so

> Ava1=791032
> per1=79
> dir1=/de/ingdp

> Ava2=1976610
> per2=86
> dir2=/de/ingdp/data1

> ....
> ...

> This will allow me to then present this on the screen.

> Any hints, clues please.

> Thank you in Advance

> Simon
> So you get 5

awk 'BEGIN { i = 0; }
     {
        ava[i] = $1;
        sub ( /%/, "", $2 );
        per[i] = $2;
        dir[i] = $3;
        i++;
     }
     END { for ( j = 0; j < i; j++ )
           {
              print ava[j], per[j], dir[j];
           }
     }' FILENAME


Tue, 12 Jul 2005 00:55:04 GMT  
 A Newbie AWK question

Quote:

>Have a problem that Awk is sure to solve, but I have hit a brick wall
>this this respect.

>I have 5 files that in them contain the avaible space on disk sets.
>these are avaiable amount , percentage used, and directory path.

>The files are like this below

>791032 79% /de/ingdp
>1976610 86% /de/ingdp/data1
>2131688 85% /de/ingdp/data2
>2273315 84% /de/ingdp/data3
>2011808 86% /de/ingdp/data4

>What I wish to do is to extract each indivdual row, and move each
>column into a designated varible so

>Ava1=791032
>per1=79
>dir1=/de/ingdp

>Ava2=1976610
>per2=86
>dir2=/de/ingdp/data1

>....
>...

>This will allow me to then present this on the screen.

awk '{sub(/%/, "", $2);print "Ava" NR "=" $1;
      print "per" NR "=" $2; print "dir" NR "=" $3}' infile

will put this out to the screen, but piping it to your shell will
set shell variables:

awk '{sub(/%/, "", $2);print "Ava" NR "=" $1;
      print "per" NR "=" $2; print "dir" NR "=" $3}' infile | sh

Chuck Demas

--
  Eat Healthy        |   _ _   | Nothing would be done at all,

  Die Anyway         |    v    | That no one could find fault with it.



Tue, 12 Jul 2005 02:08:44 GMT  
 A Newbie AWK question

[...]

% 2011808 86% /de/ingdp/data4

% What I wish to do is to extract each indivdual row, and move each
% column into a designated varible so
%
% Ava1=791032
% per1=79
% dir1=/de/ingdp

Use arrays, probably indexed on the input record number, which is
automatically stored in the variable NR:

 {
   Ava[NR] = $1
   per[NR] = $2
   dir[NR] = $3
 }

In an END block, NR will be the total number of records processed.

 END {
    # headings
    printf "%11s", ""
    for (i = 1; i <= NR; i++) {
        printf " %-30s", dir[i]
    }
    printf "\n"

    printf "%-11s", "Available:"
    for (i = 1; i <= NR; i++) {
        printf " %30d", Ava[i]
    }
    printf "\n"

    printf "%-11s", "Percentage:"
    for (i = 1; i <= NR; i++) {
        printf " %30d", per[i]
    }
    printf "\n"
 }
--

Patrick TJ McPhee
East York  Canada



Tue, 12 Jul 2005 02:33:15 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. newbie awk question

2. Newbie AWK Question

3. AWK newbie is looking for a AWK help with his 1st program

4. Newbie awk (sed??) question, regular expressions

5. Newbie question -- to make an awk program act on a collection of files

6. AWK for DOS - NewBie Question

7. awk Newbie question

8. Newbie question: how to learn (N)AWK

9. Newbie question on using System() and Awk

10. AWK Newbie Question

11. newbie question on Tcl with awk

12. Newbie Question (Was: Newbie Question...)

 

 
Powered by phpBB® Forum Software