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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nesting an if statement in awk...

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
US
I have the following situation...

the variable INP can have the following values...
3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6

i need the awk statement to return...
3, 3.1, 3.2, 3.3, 3.4, 3.5, 4

in other words, 3.0 will be 3 and 3.6 will be 4

i tried something along the lines of...

echo $INP | awk -F. '{ if($2=0 || $2=6) printf "%.0f",$0}'

This does not work. PLEASE HELP!! THANKS IN ADVANCE!!!
 
Hi

You are not testing equality, you are assigning new value to $2.
Code:
echo $INP | awk -F. '{ if($2=[highlight]=[/highlight]0 || $2=[highlight]=[/highlight]6) printf "%.0f",$0}'
But personally I would prefer it this way :
Code:
echo $INP | awk -F. '$2==0{NF--}$2==6{$1++;NF--}1'
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Thanks a bunch! Works like a charm!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top