The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 |
Newsgroups: comp.lang.awk
From: Beta <ibethim...@yahoo.com>
Date: Sun, 8 Nov 2009 19:52:52 -0800 (PST)
Local: Sun, Nov 8 2009 10:52 pm
Subject: if-command
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
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
Newsgroups: comp.lang.awk
From: Janis Papanagnou <janis_papanag...@hotmail.com>
Date: Mon, 09 Nov 2009 05:57:09 +0100
Local: Sun, Nov 8 2009 11:57 pm
Subject: Re: if-command
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
> Any help woulb be appreciated! > Best regards, > Beta
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
Newsgroups: comp.lang.awk
From: Beta <ibethim...@yahoo.com>
Date: Sun, 8 Nov 2009 21:51:14 -0800 (PST)
Local: Mon, Nov 9 2009 12:51 am
Subject: Re: if-command
On Nov 9, 11:57 am, Janis Papanagnou <janis_papanag...@hotmail.com> wrote:
> 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 > > Any help woulb be appreciated! > > Best regards, > > 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
You must Sign in before you can post messages.
You do not have the permission required to post.
|
|
|