Results 1 to 3 of 3

Thread: awk output

  1. #1
    Join Date
    Jun 2003
    Posts
    39

    Unanswered: awk output

    Hi

    I am writing a script that uses the df command which uses an awk script to do formatting this is the output of the df command..

    / (/dev/root ): 662794 blocks 213507 i-nodes
    /stand (/dev/boot ): 11868 blocks 4992 i-nodes
    /u (/dev/u ): 1320257 blocks 762824 i-nodes

    and this is my awk script which will format this input..

    BEGIN { FS = "\n" } { RS = "[ \t]+" }
    { print $1 }

    when i feed input from df -k to this awk script it prints the first two lines rather than only first line as i specify $1

    # df -k | awk -f ft.awk
    / (/dev/root ): 662793 blocks 213506 i-nodes
    /stand (/dev/boot ): 11868 blocks 4992 i-nodes


    i only need it to print first line any ideas thanks...

    xor

  2. #2
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    try this
    # df -k | grep "root" | awk -f ft.awk
    Greetings from germany
    Peter F.

  3. #3
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    To set the field seperator to a newline, use FS="". That said, if you want to use awk just to print a particular line, do it like this...

    df -k | awk 'NR==1{print; exit}'

    The use of 'exit' isn't really necessary but for larger files, you proabably wouldn't want to continue reading in lines.

    You could also use 'head' in this instance...

    df -k | head -1


    Damian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •