On 4/3/2008 10:19 PM, Ed Morton wrote:
> On 4/3/2008 9:38 PM, r wrote:
>
>>Ed Morton wrote:
>>
>>
>>
>>>On 4/3/2008 8:27 PM, r wrote:
>>>
>>>
>>>>Cesar Rabak wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>$awk -F, -f file.awk file2.csv
>>>>
>>>>
>>>>I followed your instructions, also repeating with absolute file name
>>>>paths, no syntax error but the cursor returned to the next line, no
>>>>response from command terminal. I looked at the file using a text
>>>>editor; no changes to content. What next should I check?
>>>
>>>As I said, you need to parse the file twice:
>>>
>>> awk -F, -f file.awk file2.csv file2.csv
>>>
>>>Regards,
>>>
>>> Ed.
>>
>>
>>Thank you, I forgot. Success! The command terminal shows the suitably
>>amended data. I tried to pipe the command to gedit but all I got was a
>>blank new file. So, how do I either send the command terminal display
>>output to a program such as gnumeric and save as a new file?
>
>
> Those are OS-specific questions, not awk questions but if you're on UNIX
then
> assuming "gnumeric" is some program that can read from a pipe:
>
> awk -F, -f file.awk file2.csv file2.csv | gnumeric
>
> and to just save the output to a file:
>
> awk -F, -f file.awk file2.csv file2.csv > newfile
>
>
>>Could you tell me which section of the documentation explains why the
file needs
>>to be read twice, please?
>
>
> It's not a documentation thing, your problem just requires a 2-pass
solution.
> The first time to identify which columns always have the null value, the
second
> to output just the columns that have at least one non-null value.
>
>
>>From the command terminal instruction awk, am I right to conclude that
>>-F, means "comma is the file delimiter, or separator"?
>
>
> Yes.
>
> Ed.
>
By the way, since you're saving the script in a file, it'd be appropriate
to set
FS in the script rather than on the command line, and you can specifically
tell
awk to parse a file twice by adding the supplied file name again to the
end of
it's argument array, so you could change the script to:
BEGIN {
FS=","
ARGV[ARGC++]=ARGV[ARGC-1]
}
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
}
and invoke it as just:
awk -f file.awk file2.csv
Regards,
Ed.


|