[KLUG Programming] sorting, uniq'ing, and grepping
Tony Gettig
programming@kalamazoolinux.org
Mon, 14 Jul 2003 11:36:35 -0400
Quoting "Robert G. Brown" <bob@acm.org>:
> On Mon, 14 Jul 2003 10:11:21 -0400, Tony Gettig <tony@gettig.net> wrote:
>
> >I've got a process that I am trying to convert to a C program....
> >I've got the file combining working....
> I'd have to see your code. The wonderful thing about pseudocode is that
> you get a picture of what you have to do, and implementing it in something
> "real" is even better, since it shows itself correct, at least informally,
> over time.
>
> The problem with the pseudocode you've got is that it does not suggest good
> implementation methods.. you've noted the steps in some high level (command
> level) way, but you have not shown how the work actually gets done.
Actually, with the exception of the filenames, my psuedocode lines are the
actual commands I'm running manually. Here's an example with reasonably
realistic filenames:
cat 031703.dat > full.dat
cat 032403.dat >> full.dat
sort full.dat > sort.dat
uniq -uw7 > uniq.dat
grep 03/17/03 > remove.dat
grep 03/24/03 > import.dat
I then run import.dat and remove.dat through a perl script to create the LDIF,
CSV, and batch files.
So you see, my psuedocode is actually less psuedo than real. :)
> >It compiles on all the platforms listed above using different compilers....
> Probably because you're being a good citizen and writing in ANSI C or
> something close to it. A good practice, IMO.
I figure by sticking to a standard, I have a better chance of succeeding in
the long term.
I've posted my code thus far to http://gettig.net/files/myprog.c I am starting
work on the parsing function today. It will basically read in the sorted and
uniq data line by line, filling variables and writing to respective files. I
think if I can get this data sorted and uniq'd programatically, I can reach my
goal.
Oh yeah, an afterthought: the raw data files I'm dealing are ASCII text, fixed
width. Hence my uniq -uw7, which happens to be the eventual username.
>
> >Am I nuts? Should I just stick to the shell?
> Nah, this is a good idea, and quite feasible. If you are slavishly following
> your own psuedocode, you're probably writing too much code, but you'll reach
> your goal in due course.
Thanks for the affirmation. I just read Adam's affirming email as well. I
reckon I'm heading in the right direction with this. It's not just a project
that I need to do, but I really want to get better at C. And what better way
than actually doing something useful and practical.
> >Can you tell I'm not a full time programmer? :)
> >From the moment I met you, Tony! :)
Does it count that I aspire to be one when I grow up? :)
Thanks a ton for the help!
--
Tony Gettig
Voiceovers, PGP key, and more at
http://gettig.net