If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk output

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-27-03, 21:22
xor xor is offline
Registered User
 
Join Date: Jun 2003
Posts: 39
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
Reply With Quote
  #2 (permalink)  
Old 11-28-03, 15:06
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
try this
# df -k | grep "root" | awk -f ft.awk
__________________
Greetings from germany
Peter F.
Reply With Quote
  #3 (permalink)  
Old 12-02-03, 09:02
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On