merging 2 files

Randal Schwartz merlyn at iwarp.intel.com
Fri May 4 10:46:43 AEST 1990


In article <757 at sagpd1.UUCP>, jharkins at sagpd1 (Jim Harkins) writes:
| 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.

An all-in-one Perl solution...

################################################## snip snip
#!/usr/local/bin/perl

@names = split(/\n/, <<END_OF_NAMES);
FooBar
blaTZ
GRMblE
WhEe
END_OF_NAMES

$cmd = "study;\n";

for $name (@names) {
	($lcname = $name) =~ y/A-Z/a-z/;
	$cmd .= "s/\\b$name\\b/$lcname/g;\n";
}

while (<>) {
	eval $cmd;
	print;
}
################################################## snip snip

printf "%s", "Just another Perl hacker,"
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/



More information about the Comp.unix.questions mailing list