substitue in vi

Michael J. Chinni, SMCAR-CCS-E mchinni at pica.army.mil
Thu Aug 17 07:30:01 AEST 1989


Thanks to all who took the time to answer my question:
>How can i do the following:
>	for every word (word as far as vi is concerned) in a file, 
>	capitalize the first letter
>

I received quite a few answers.  All answers but one, were variations on:
:%s/\<[a-z]/\u&/g

which is what I used. This worked exactly as I asked (even as I intended - i.e.
only change the letter if it is lower-case already). 

The only answer NOT of this form was one that used awk. Although this needs to
be expanded for the entire alphabet the author DID tell me this:
	awk 'BEGIN {
		upper = "ABCDEF";
		lower = "abcdef";
	}
	{
		out = "";
		for (i=1; i <= length($4);i++) {
			if ((cpos = index(lower,c = substr($4,i,1))) > 0 )
				c = substr(upper,cpos,1);
			out = out c;
		}
		printf("%s %s %s %s\n",$1, $2, $3, out);
	}'

Thanks again to all who answered.

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
			    Michael J. Chinni
      Chief Scientist, Simulation Techniques and Workplace Automation Team
	 US Army Armament Research, Development, and Engineering Center
 User to skeleton sitting at cobweb   () Picatinny Arsenal, New Jersey  
    and dust covered workstation      () ARPA: mchinni at pica.army.mil
      "System been down long?"        () UUCP: ...!uunet!pica.army.mil!mchinni
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



More information about the Comp.unix.questions mailing list