Re: simple database solution without root access
Bob Proulx wrote:
> kamaraju kusumanchi wrote:
> > I have some data in text format organized as follows
> >
> > field_1,field_2,field_3,...,field_9
> > val_1_1,val_1_2,val_1_3,...,val_1_9
> > val_2_1,val_2_2,val_2_3,...,val_2_9
> > ...
> > val_100_1,val_100_2,val_100_3,...,val_100_9
> >
> >
> > I want to do database (sql) like operations on this data. For example,
>
> It sounds like you what you want is what many call "data munging".
> Such as "data munging with X" where X is awk, perl, python, ruby, or
> other programming language. There is even a classic book Data Munging
> with Perl that specializes in such things. I tend to use awk for such
> things since they can be done as a one-liner fairly easily.
>
> awk -F, '$2==5{sum+=$8}END{printf("%d\n",sum);}' datafile
>
> awk -F, '$2==42 && $7 == 37' datafile
>
> awk -F, '$1 ~ /PATTERN1/ && $1 ~ /PATTERN2/' datafile
>
> perl -F, -lane 'END{print $t} $t += $F[7] if $F[1] == 5'
>
> And similar for other languages. You could even load a full CSV
> module if needed.
Those are helpful examples. I'd forgotten about perl's
autosplit mode (the -a in -lane) which splits the input
lines to @F. It makes sense that the -F option is the
same in perl as for awk.
Joel
> Bob
--
Joel Roth
Reply to: