Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

> < operators in awk 1

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL

Hello,
could someone please explain why in examples below awk with $5>"57" returns red line too? With $5<"57" doesn't.

Code:
$ df -v -g >/tmp/output
$ cat /tmp/output
Filesystem    GB blocks      Used      Free %Used    Iused    Ifree %Iused Mounted on
/dev/hd4           0.50      0.19      0.31   39%    10132    73117    13% /
/dev/hd2           2.25      2.09      0.16   93%    45467    42195    52% /usr
/dev/hd9var        0.44      0.35      0.09   80%     8219    22854    27% /var
/dev/hd3           0.12      0.00      0.12    2%       41    31969     1% /tmp
/dev/hd1           0.06      0.00      0.06    1%        5    14543     1% /home
/dev/hd11admin      0.12      0.00      0.12    1%        5    29133     1% /admin
/proc                 -         -         -    -         -        -     -  /proc
/dev/hd10opt       0.44      0.25      0.19   57%     8956    45165    17% /opt
/dev/livedump      0.25      0.00      0.25    1%        4    58200     1% /var/adm/ras/livedump
$ awk 'NR==1 || $5>"51"' /tmp/output
Filesystem    GB blocks      Used      Free %Used    Iused    Ifree %Iused Mounted on
/dev/hd2           2.25      2.09      0.16   93%    45467    42195    52% /usr
/dev/hd9var        0.44      0.35      0.09   80%     8219    22854    27% /var
/dev/hd10opt       0.44      0.25      0.19   57%     8956    45165    17% /opt
$ [bold]awk 'NR==1 || $5>"57"' /tmp/output[/bold]
Filesystem    GB blocks      Used      Free %Used    Iused    Ifree %Iused Mounted on
/dev/hd2           2.25      2.09      0.16   93%    45467    42195    52% /usr
/dev/hd9var        0.44      0.35      0.09   80%     8219    22854    27% /var
[red]/dev/hd10opt       0.44      0.25      0.19   57%     8956    45165    17% /opt[/red]
$ [bold]awk 'NR==1 || $5<"57"' /tmp/output[/bold]
Filesystem    GB blocks      Used      Free %Used    Iused    Ifree %Iused Mounted on
/dev/hd4           0.50      0.19      0.31   39%    10132    73117    13% /
/dev/hd3           0.12      0.00      0.12    2%       41    31969     1% /tmp
/dev/hd1           0.06      0.00      0.06    1%        5    14543     1% /home
/dev/hd11admin      0.12      0.00      0.12    1%        5    29133     1% /admin
/proc                 -         -         -    -         -        -     -  /proc
/dev/livedump      0.25      0.00      0.25    1%        4    58200     1% /var/adm/ras/livedump
$ ( awk 'NR==1 || $5>"57"' /tmp/output ; awk '$5<"57"' /tmp/output )|sort|cksum
905655793 825
$ sort /tmp/output|cksum
905655793 825
$ awk 'NR==1 || $5=="57"' /tmp/output
Filesystem    GB blocks      Used      Free %Used    Iused    Ifree %Iused Mounted on
$ awk 'NR==1 || $5~/^57/' /tmp/output
Filesystem    GB blocks      Used      Free %Used    Iused    Ifree %Iused Mounted on
/dev/hd10opt       0.44      0.25      0.19   57%     8956    45165    17% /opt
$
 

Because the fifth field ($5) include the percent sign and your condition $5<"57" does not.
[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
ok, I used such workaround

df -v -g|sed s/%/\ abc\ /g|awk -va=94 'NR==1 || $5>a'|sed s/\ abc\ /%/g
 
Why not simply this ?
Code:
df -v -g | awk -F'[ \t%]+' -va=94 'NR==1||$5>a'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top