Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

if-command

0 views
Skip to first unread message

Beta

unread,
Nov 8, 2009, 10:52:52 PM11/8/09
to
Hi,

I have an input file (input.dat):
0 0.24 0.35 0.5 0.6 0.2 0.12
1 0.4 0.2 0.45 0.55 0.3 0.40
2 0.3 0.3 0.4 0.4 0.45 0.5
3 0.2 0.1 0.4 0.5 0.34 0.2
then I use if command :
awk '{if ($2 < 0.35) print $1, 1, $2, $3, $4, $5, $6, $7; else print
$1, 0, $2, $3, $4, $5, $6, $7}' input.dat > output.dat
The output.dat:
0 1 0.35 0.5 0.6 0.2 0.12
1 0 0.2 0.45 0.55 0.3 0.40
2 1 0.3 0.4 0.4 0.45 0.5
3 1 0.1 0.4 0.5 0.34 0.2
and I can repeat the if-command for the next column, so that the final
output:
0 1 1 0 0 1 1
1 1 1 0 0 1 0
2 1 1 0 0 0 0
3 1 1 0 0 1 1
Does anyone know the short way to perform the command?

Any help woulb be appreciated!

Best regards,
Beta


Janis Papanagnou

unread,
Nov 8, 2009, 11:57:09 PM11/8/09
to
Beta wrote:
> Hi,
>
> I have an input file (input.dat):
> 0 0.24 0.35 0.5 0.6 0.2 0.12
> 1 0.4 0.2 0.45 0.55 0.3 0.40
> 2 0.3 0.3 0.4 0.4 0.45 0.5
> 3 0.2 0.1 0.4 0.5 0.34 0.2
> then I use if command :
> awk '{if ($2 < 0.35) print $1, 1, $2, $3, $4, $5, $6, $7; else print
> $1, 0, $2, $3, $4, $5, $6, $7}' input.dat > output.dat
> The output.dat:
> 0 1 0.35 0.5 0.6 0.2 0.12
> 1 0 0.2 0.45 0.55 0.3 0.40
> 2 1 0.3 0.4 0.4 0.45 0.5
> 3 1 0.1 0.4 0.5 0.34 0.2
> and I can repeat the if-command for the next column, so that the final
> output:
> 0 1 1 0 0 1 1
> 1 1 1 0 0 1 0
> 2 1 1 0 0 0 0
> 3 1 1 0 0 1 1

IIUC, I think you've got your numbers wrong; shouldn't that be...?

0 1 0 0 0 1 1
1 0 1 0 0 1 0


2 1 1 0 0 0 0
3 1 1 0 0 1 1

> Does anyone know the short way to perform the command?

awk -v t=0.35 '{ print $1, $2<t, $3<t, $4<t, $5<t, $6<t, $7<t } '

Janis

Beta

unread,
Nov 9, 2009, 12:51:14 AM11/9/09
to
On Nov 9, 11:57 am, Janis Papanagnou <janis_papanag...@hotmail.com>
wrote:
> > Beta- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

You're right and the command works very nice. Thank you very much!

Best regard,
Beta

0 new messages