Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!ucsd!ucbvax!agate!e260-3f!c60c-3cf From: c60c-3cf@e260-3f.berkeley.edu (Dan Kogai) Newsgroups: comp.unix.questions Subject: Re: merging 2 files Keywords: sed awk perl join Message-ID: <1990May4.163348.1686@agate.berkeley.edu> Date: 4 May 90 16:33:48 GMT References: <757@sagpd1.UUCP> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Organization: UC Bezerkeley Lines: 88 In article <757@sagpd1.UUCP> jharkins@sagpd1.UUCP (Jim Harkins) writes: In article <757@sagpd1.UUCP> you write: >I need to change a lot of words with mixed upper and lower case letters into >words of all lower case letters, from there I'm going to make a sed script >to actually modify the words in our source. So how do I make my list? >For example, I want to convert the list > >FooBar >blaTZ >GRMblE >WhEe > >into > >FooBar foobar >blaTZ blatz >GRMblE grmble >WhEe whee > >(from this second list it's trivial to create lines of sed commands like >'/FooBar/foobar/g', and there are around 800 words in my list) > >Right now I have 2 files, one with the upper/lower case names, the second >with just lower case names. I think I've been going down the wrong path >here though. I'm now thinking of using sed directly but I'm no sed wizard. >Join may also do the job but I'm having trouble deciphering the man page >and none of my experiments to date have remotely resembled what I'm after. > >So, has anyone got any advice (outside of having a flunky use vi :-)? >Thanks in advance. Just write eine kline C code like the following: /* * mergeline.c */ #include #include main(int argc, char **argv){ FILE *file1, *file2; char buf1[1024], buf2[1024] if (argc != 3){ /* error */ fprintf(stderr "%s:usage: %s file1 file2\n", argv[0], argv[0]); exit(1); } file1 = fopen(argv[1], "r"), file2 = fropen(argv[2], "r"); if (!file1){ fprintf(stderr "%s: couldn't open file: %s", argv[0], argv[1]); exit(1); } if (!file2){ fprintf(stderr "%s: couldn't open file: %s", argv[0], argv[2]); exit(1); } while (fgets(buf1, 1024, stdin) && fgets(buf2, 1024, stdout)){ /* strtok is necessary to get rid of NL fgets gives ya! */ printf("%s\t%s\n", strtok(buf1,'\n'), strtok(buf2, '\n')); } } /* That's it! */ And you compile the program and give such name as "merge", then run merge file1, file2. I chose tab to separate 2 entries but you can modify my program or same thing could be done via sed|awk|etc. Maybe I shoul've suggested using perl but I'm not perl expert and c looked much easier. Good luck. >My new investment plan GUARENTEES a 50% rate of return! Just mail me $10,000 >and I promise you'll get $5,000 back. Well, I don't take your offer. You can be Craig Shergold's life insurance contractor ;) --- ################## Dan The "I grok therefore I am God" Man + ____ __ __ + (Aka Dan Kogai) + ||__||__| + E-mail: dankg@ocf.berkeley.edu + ____| ______ + Voice: 415-549-6111 + | |__|__| + USnail: 1730 Laloma Berkeley, CA 94709 + |___ |__|__| + U.S.A + |____|____ + Disclaimer: I'd rather be blackmailed for my long .sig + \_| | + than give up my cool name in Kanji. And my + <- THE MAN -> + citizenship of People's Republic o' Berkeley ################## has nothing 2 do w/ whatever I post, ThanQ. --