Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: delete colu...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 36 Topic 2215 of 2236
Post > Topic >>

Re: delete columns csv file

by Ed Morton <morton@[EMAIL PROTECTED] > Apr 4, 2008 at 08:04 AM

On 4/4/2008 12:32 AM, Hermann Peifer wrote:
> Ed Morton wrote:
> 
>>On 4/3/2008 3:27 PM, Hermann Peifer wrote:
>>
>>>Ed Morton wrote:
>>>
>>>
>>>>On 4/3/2008 2:19 PM, r wrote:
>>>>
>>>>
>>>>>Readers,
>>>>>
>>>>>I have a csv file (greater than 256 columns hence unable to open and
>>>>>edit in
>>>>>spreadsheet) of the following format:
>>>>>
>>>>>column header1, column header2, column header3
>>>>>1,0.0e0,0.0e0,5e-6
>>>>>2,0.0e0,0.0e0,6e-7
>>>>>3,0.0e0,0.0e0,0.0e0
>>>>>
>>>>>I want to perform: "if column headerx contains only values of 0.0e0,
>>>>>delete the column (including the column header).
>>>>>
>>>>>Can a script be provided and then a discussion of how this problem is
>>>>>solved please (novice)?
>>>>>
>>>>>Yours,
>>>>>
>>>>>mandriva 2008
>>>>
>>>>You need to parse the file twice:
>>>>
>>>>awk -F, '
>>>>NR==FNR {
>>>>  if (NR>1)
>>>>     for (i=1;i<=NF;i++)
>>>>        if ($i"" != "0.0e0")
>>>>           good[i]
>>>>  next
>>>>}
>>>>{  out=sep=""
>>>>  for (i=1;i<=NF;i++) {
>>>>      if (i in good)
>>>>         out = out sep $i
>>>>      sep=FS
>>>>  } print out
>>>>}' file file
>>>>
>>>>Regards,
>>>>
>>>>	Ed.
>>>>
>>>
>>>Shouldn't "if column headerx contains only values of..." result into:
>>>
>>>if (NR==1)
>>>
>>
>>That's what I thought at first too, but then I reread it and I think it
means
>>"if all values in a given column are ....".
>>
>>	Ed.
>>
> 
> 
> OK. Then it depends on what the OP really meant.
> 
> Couldn't: if ($i"" != "0.0e0") be replaced by a simple: if ($i)  ?

No, because the OP asked specifically for a comparison to "0.0e0" not for
"0" or
"". It probably could've been just ($i != "0.0e0") but I couldn't be
bothered
thinking about the string/numeric comparison rules...

> And I wasn't sure what the first pair of double quotes in this condition

> was meant to do?

Just ensuring a string comparison by making both sides of the comparison
strings.

	Ed.




 36 Posts in Topic:
delete columns csv file
r <inpost@[EMAIL PROTE  2008-04-03 12:19:05 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-03 14:51:04 
Re: delete columns csv file
Hermann Peifer <peifer  2008-04-03 22:27:16 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-03 15:42:10 
Re: delete columns csv file
Hermann Peifer <peifer  2008-04-04 07:32:38 
Re: delete columns csv file
pk <pk@[EMAIL PROTECTE  2008-04-04 09:23:00 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-04 08:04:52 
Re: delete columns csv file
r <inpost@[EMAIL PROTE  2008-04-03 14:00:32 
Re: delete columns csv file
Cesar Rabak <csrabak@[  2008-04-03 20:58:21 
Re: delete columns csv file
r <inpost@[EMAIL PROTE  2008-04-03 14:04:21 
Re: delete columns csv file
r <inpost@[EMAIL PROTE  2008-04-03 18:27:55 
Re: delete columns csv file
pop <p_o_p@[EMAIL PROT  2008-04-03 20:45:14 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-03 20:46:10 
Re: delete columns csv file
r <inpost@[EMAIL PROTE  2008-04-03 19:38:05 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-03 22:19:49 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-04 08:38:19 
Re: delete columns csv file
Janis <janis_papanagno  2008-04-04 01:31:18 
Re: delete columns csv file
pk <pk@[EMAIL PROTECTE  2008-04-04 11:19:03 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-04 08:20:19 
Re: delete columns csv file
pk <pk@[EMAIL PROTECTE  2008-04-04 15:51:14 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-04 08:53:58 
Re: delete columns csv file
pk <pk@[EMAIL PROTECTE  2008-04-04 18:31:55 
Re: delete columns csv file
Janis <janis_papanagno  2008-04-04 05:19:46 
Re: delete columns csv file
pk <pk@[EMAIL PROTECTE  2008-04-04 15:37:07 
Re: delete columns csv file
Hermann Peifer <peifer  2008-04-04 07:28:48 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-04 09:41:43 
Re: delete columns csv file
pk <pk@[EMAIL PROTECTE  2008-04-04 18:33:03 
Re: delete columns csv file
Hermann Peifer <peifer  2008-04-04 19:13:07 
Re: delete columns csv file
r <inpost@[EMAIL PROTE  2008-04-16 07:08:05 
Re: delete columns csv file
Ed Morton <morton@[EMA  2008-04-16 23:35:25 
Re: delete columns csv file
Janis <janis_papanagno  2008-04-16 08:16:29 
Re: delete columns csv file
gazelle@[EMAIL PROTECTED]  2008-04-16 15:33:42 
Re: delete columns csv file
r <inpost@[EMAIL PROTE  2008-04-16 14:58:52 
Re: delete columns csv file
Janis Papanagnou <Jani  2008-04-17 01:55:39 
Re: delete columns csv file
r <inpost@[EMAIL PROTE  2008-04-17 16:01:03 
Re: delete columns csv file
Janis Papanagnou <Jani  2008-04-18 01:54:47 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 5:51:25 CDT 2008.