reader@wsl.dec.com (News Reader) (12/11/90)
Is there an easy way to change the whole file from upper case to lower case or vice versa? I don't want to do 26 substitutions to change character by character.
reader@wsl.dec.com (News Reader) (12/11/90)
Is there an easy way to change the whole file from upper case to lower case or vice versa? I don't want to do 26 substitutions to change character by character. -- ...Reading news is my job......
rouben@math13.math.umbc.edu (Rouben Rostamian) (12/11/90)
In article <1990Dec11.005842.13795@pa.dec.com> reader@wsl.dec.com (News Reader) writes: > >Is there an easy way to change the whole file from upper case to lower case or >vice versa? I don't want to do 26 substitutions to change character by >character. If you insist on doing it in vi, here it is: :%s/./\U&/g or alternatively: :%s/[a-z]/\U&/g Both of these convert characters to uppercase. To convert to lowercase replace "U" with "L". If you are not already editing the file, you should not start up vi; use tr(1) instead: tr '[a-z]' '[A-Z]' <infile >outfile Now let's see a slew of solutions using sed, ed, ex, awk, perl, C, BASIC flow in. :-( -- Rouben Rostamian Telephone: (301) 455-2458 Department of Mathematics and Statistics e-mail: University of Maryland Baltimore County bitnet: rostamian@umbc Baltimore, MD 21228, U.S.A. internet: rostamian@umbc3.umbc.edu
brister@decwrl.dec.com (James Brister) (12/11/90)
On Tue, 11 Dec 90 01:18:04 GMT, reader@wsl.dec.com (News Reader) said: > Is there an easy way to change the whole file from upper case to lower > case or vice versa? I don't want to do 26 substitutions to change > character by character. You're better off using tr(1). i.e.: % tr '[A-Z]' '[a-z]' < infile > outfile for upper to lower James -- James Brister brister@decwrl.dec.com DEC Western Software Lab., Palo Alto, CA {uunet,sun,pyramid}!decwrl!brister
sanjiv@hoss.unl.edu (Sanjiv K. Bhatia) (12/11/90)
In article <1990Dec11.011804.14702@pa.dec.com> reader@wsl.dec.com (News Reader) writes: > >Is there an easy way to change the whole file from upper case to lower case or >vice versa? I don't want to do 26 substitutions to change character by >character. Here it is: :%!tr "[A-Z]" "[a-z]" > >-- >...Reading news is my job...... -- Sanjiv K. Bhatia Department of Computer Science sanjiv@fergvax.unl.edu Ferguson Hall 115 voice: (402)-472-3485 University of Nebraska - Lincoln fax: (402)-472-7767 Lincoln, NE 68588-0115
tchrist@convex.COM (Tom Christiansen) (12/11/90)
In article <1990Dec11.005842.13795@pa.dec.com> reader@wsl.dec.com (News Reader) writes: > >Is there an easy way to change the whole file from upper case to lower case or >vice versa? I don't want to do 26 substitutions to change character by >character. INTERNALLY: :%s/.*/\U&/ :%s/.*/\L&/ TOOLISHLY: :%!tr a-z A-Z # real unix :%!tr A-Z a-z :%!tr '[a-z]' '[A-Z]' # bad unix :-) :%!tr '[A-Z]' '[a-z]' :%!sed y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ :%!sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ :%!gawk '{print tolower($0)}' :%!gawk '{print toupper($0)}' :%!nawk '{print tolower}' # nawk assumes $0, gawk doesn't :%!nawk '{print toupper}' :%!perl -pe y/a-z/A-Z/ # for sed folks :%!perl -pe y/A-Z/a-z/ :%!perl -pe tr/a-z/A-Z/ # for sh folks :%!perl -pe tr/A-Z/a-z/ --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "With a kernel dive, all things are possible, but it sure makes it hard to look at yourself in the mirror the next morning." -me
mayoff@cs.utexas.edu (Robert Mayoff) (12/12/90)
In article <1990Dec11.005842.13795@pa.dec.com> reader@wsl.dec.com (News Reader) writes: >Is there an easy way to change the whole file from upper case to lower case or >vice versa? Yes. The editor-only way to do it is to use this substitution command: :%s/.*/\L&/ but I prefer the (IMHO) less-cryptic, easier-to-remember, although slightly slower, solution: :%!tr A-Z a-z which uses the tr (translate) command to turn uppercase into lowercase. The reverse transformation can be accomplished with :%s/.*/\U&/ or :%!tr a-z A-Z -- /_ rob <mayoff@cs.utexas.edu> /_ Fun things to do with UNIX (#2 in a series): / echo "rsh `hostname` -n source eat.cpu &" > eat.cpu; source eat.cpu
tchrist@convex.COM (Tom Christiansen) (12/12/90)
In article <ED.90Dec11222413@lvw6.lvw.fac.com> ed@lvw6.lvw.fac.com (Ed Allen) writes: >From within vi you could try: >:%s/./\U&/g >Which tells vi: >on every line of the buffer, > substitute for each char the UPPERCASE of that char I've seen a lot of people suggest this, but it's pretty suboptimal. Watch: % cp /etc/termcap . % /bin/time sh -c '(echo "%s/.*/\U&/";echo x)|ex - termcap' 2.502023 real 1.353925 user 0.423176 sys % cp /etc/termcap . % /bin/time sh -c '(echo "%s/./\U&/g";echo x)|ex - termcap' 18.158108 real 8.973235 user 0.462504 sys Just do it all at once. If you're going to do one character at a time, then you could just use \u, which only affects the next chararcter --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "With a kernel dive, all things are possible, but it sure makes it hard to look at yourself in the mirror the next morning." -me
ed@lvw6.lvw.fac.com (Ed Allen) (12/12/90)
>In article <1990Dec11.011804.14702@pa.dec.com> reader@wsl.dec.com (News Reader) writes: > > Path: wdl1.wdl.loral.com!mips!dimacs.rutgers.edu!aramis.rutgers.edu!paul.rutgers.edu!njin!princeton!udel!haven!decuac!pa.dec.com!reader > From: reader@wsl.dec.com (News Reader) > Newsgroups: comp.editors > Date: 11 Dec 90 01:18:04 GMT > Sender: news reader > Followup-To: comp.editors > Distribution: na > Organization: DEC > Lines: 8 > > > Is there an easy way to change the whole file from upper case to lower case or > vice versa? I don't want to do 26 substitutions to change character by > character. > From within vi you could try: :%s/./\U&/g Which tells vi: on every line of the buffer, substitute for each char the UPPERCASE of that char -- Never trust a man who wears white shoes. | Ed Allen Vote Libertarian... Scare the Hell out of 'em. | Loral Command & Contr. Sys. "Sure the game is rigged! But if you don't play | ed@lvw6.lvw.loral.com you can't win!"
timm@skye.sybase.com (Tim Meazell) (12/20/90)
In article <1990Dec11.041717.18604@hoss.unl.edu> sanjiv@hoss.unl.edu (Sanjiv K. Bhatia) writes: >In article <1990Dec11.011804.14702@pa.dec.com> reader@wsl.dec.com (News Reader) writes: >> >>Is there an easy way to change the whole file from upper case to lower case or >>vice versa? I don't want to do 26 substitutions to change character by >>character. > >Here it is: > > :%!tr "[A-Z]" "[a-z]" > Having had considerable trouble with "tr" and its various implementations, my favorite is the more portable: :%!dd conv=ucase Haven't been able to get rid of the 2 diagnostic lines... ----------------------------------------------------------------- Timothy A. Meazell | |\/\/\/\/| timm@sybase.com | | | (415) 596-3590 | | | | | (e) (e) | | _) | (c ,_____\ | | (__( Like, don't have a cow, man!! | | / | /____\
asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) (12/22/90)
In article <1990Dec11.011804.14702@pa.dec.com> reader@wsl.dec.com (News Reader) writes: > > Is there an easy way to change the whole file from upper case to lower case or > vice versa? I don't want to do 26 substitutions to change character by > character. > IS THERE AN EASY WAY TO CHANGE THE WHOLE FILE FROM UPPER CASE TO LOWER CASE OR VICE VERSA? I DON'T WANT TO DO 26 SUBSTITUTIONS TO CHANGE CHARACTER BY CHARACTER. Hmm, yes, I believe there is! Just a combinations of solutions I've seen. To up-case a single paragraph, you can type: {!}tr '[a-z]' '[A-Z]' which will conveniently pipe the paragraph into the tr (translate) command. To translate the entire file, set your cursor at the beginning and enter: !Gtr '[a-z]' '[A-Z]' I've just learned of this method, deduced from the '{!}fmt' command I've read in these postings. This is an amazingly powerful feature! If there's nearly anything at all you want to do from the editor that it doesn't do now, just write it in C and there it is! Altho, it's extremely likely there's a utility, such as 'fmt', which already does it. In fact, I'm thinking of writing my own version of 'fmt' that will take hyphens into account, plus auto-hyphening common suffixes and prefixes. So that you'd change, for example, "hyphening" to "hyphen- ing", and back, as required. Or does *that* already exist somewhere, too? -- asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) ========================= Opinions are Mine, Typos belong to /usr/ucb/vi "We're sorry, but the reality you have dialed is no longer in service. Please check the value of pi, or see your SysOp for assistance." UUCP: hplabs!felix!asylvain ============================================