Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Change Uppercase to Lowercase with some exceptions Post 302428706 by pseudocoder on Thursday 10th of June 2010 02:40:17 PM
Old 06-10-2010
The first if statement checks if all 3 columns from a row contain uppercase A-Z only.
The second statement checks if the first two columns from a row contain uppercase A-Z only AND if the third column contains a dot.

Code:
#!/usr/local/bin/perl

use strict;
use warnings;

my $infile='sunny.dat';

open(I,$infile) or die "Error: $! \n";
my @arr=<I>;
close(I);

foreach my $row (@arr) {
  chomp($row);

  my @rowele=split(/ /,$row);

   if ($rowele[0] =~ /^[A-Z]*$/ && $rowele[1] =~ /^[A-Z]*$/ && $rowele[2] =~ /^[A-Z]*$/) {

	$rowele[0] =~ tr/A-Z/a-z/;
        $rowele[1] =~ tr/A-Z/a-z/;
	$rowele[2] =~ tr/A-Z/a-z/;

 	print "$rowele[0] $rowele[1] $rowele[2] \n";
	next;
   }

   if ($rowele[0] =~ /^[A-Z]*$/ && $rowele[1] =~ /^[A-Z]*$/ && $rowele[2] =~ /[\.]/) {

	$rowele[0] =~ tr/A-Z/a-z/;
	$rowele[1] =~ tr/A-Z/a-z/;

 	print "$rowele[0] $rowele[1] $rowele[2] \n";
	next;
   }

   print "$rowele[0] $rowele[1] $rowele[2] \n";

}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

uppercase to lowercase

Greetings & Happy New Years To All! A client of mine FTP'ed their files up to the server and it all ended up being in UPPERCASE when it all should be in lowercase. Is there a builtin command or a script anyone knows of that will automagically convert all files to lowercase? Please advise asap... (4 Replies)
Discussion started by: webex
4 Replies

2. UNIX for Dummies Questions & Answers

Need to change filenames in a particular directory from lowercase to UPPERCASE

Hi, I need a shell script which changes a bunch of files in a particular directory from lowercase to UPPERCASE. I am not very familiar with shell scripts so a detailed explanation would be greatly appreciated!!!! Thanks ini advance! :) (7 Replies)
Discussion started by: Duke_Lukem
7 Replies

3. Shell Programming and Scripting

UPPERCASE to lowercase with no overwriting?

Hey, I've just started learning shell script today. How would I write a bash script file that changes file names from uppercase to lowercase in that directory, the program should warn the user and NOT overwrite the existing file if it's already in lowercase? for example in a directory i... (1 Reply)
Discussion started by: lgd923
1 Replies

4. AIX

Lowercase to Uppercase

Inside a script I have 2 variables COMP=cy and PT=t. further down the same script I require at the same line to call those 2 variables the first time uppercase and after lowercase ${COMP}${PT}ACE,${COMP}${PT}ace. Can somebody help me Thanks in advance George Govotsis (7 Replies)
Discussion started by: ggovotsis
7 Replies

5. UNIX for Dummies Questions & Answers

uppercase to lowercase

i have no variable and no file i just want to convert AJIT to ajit with some command in UNIX can anybody help (4 Replies)
Discussion started by: ajit.yadav83
4 Replies

6. Shell Programming and Scripting

indentation and lowercase to uppercase

hi, i need to write a bash script that does two things. the program will take from the command line a file name, which is a C code, and an integer, which is the size of my indentation i would then have to indent every nested code by the number of columns provided by the user in the... (1 Reply)
Discussion started by: kratos.
1 Replies

7. UNIX Desktop Questions & Answers

Unix: lowercase to uppercase

I just started to learn unix... and i needed to make a basic script. i need to 1. read a file (.txt) 2. count the words of EVERY sentece 3. sentences with odd number of words need to be converted into lowercase sentences with even number of words need to be converted into uppercase ... (6 Replies)
Discussion started by: chilli1988
6 Replies

8. UNIX for Dummies Questions & Answers

UPPERCASE to lowercase

Hi All, i have a file and i want to convert all uppercase letters to lowercase letters which are in my file. how can i do this. Thanx (3 Replies)
Discussion started by: temhem
3 Replies

9. Shell Programming and Scripting

Convert lowercase to uppercase

listprocs.sh contains ps -ef | grep "swikar" 1) Write a shell script to convert an input file to all upper case. Name your shell script toupper.sh. Hint: tr ' ' ' ' will convert all lower case letters to upper case To use your script, try the following command: cat... (1 Reply)
Discussion started by: swikar
1 Replies

10. Shell Programming and Scripting

Uppercase to lowercase

Hello, I have a list of files in a directory whose names are all in uppercasse, including the file format for eg *.MP3 . I would like to convert these to the normal way we write it ie ABC.MP3 to be converted to Abc.mp3 . I know that this can be done manually by using a lot of "mv" or rename... (6 Replies)
Discussion started by: ajayram
6 Replies
btparse::doc::bt_misc(3)					      btparse						  btparse::doc::bt_misc(3)

NAME
bt_misc - miscellaneous BibTeX-like string-processing utilities SYNOPSIS
void bt_purify_string (char * string, btshort options); void bt_change_case (char transform, char * string, btshort options); DESCRIPTION
bt_purify_string() void bt_purify_string (char * string, btshort options); "Purifies" a "string" in the BibTeX way (usually used for generating sort keys). "string" is modified in-place. "options" is currently unused; just set it to zero for future compatibility. Purification consists of copying alphanumeric characters, converting hyphens and ties to space, copying spaces, and skipping (almost) everything else. "Almost" because "special characters" (used for accented and non-English letters) are handled specially. Recall that a BibTeX special character is any brace-group that starts at brace-depth zero whose first character is a backslash. For instance, the string {foo bar}Herr M"uller went from {P{ r}erov} to {AA}rhus contains two special characters: "{foo bar}" and "AA". Neither the ""u" nor the " r" are special characters, because they are not at the right brace depth. Special characters are handled as follows: if the control sequence (the TeX command that follows the backslash) is recognized as one of LaTeX's "foreign letters" ("oe", "ae", "o", "l", "ae", "ss", plus uppercase versions), then it is converted to a reasonable English approximation by stripping the backslash and converting the second character (if any) to lowercase; thus, "{AA}" in the above example would become simply "Aa". All other control sequences in a special character are stripped, as are all non-alphabetic characters. For example the above string, after "purification," becomes barHerr Muller went from Pr rerov to Aarhus Obviously, something has gone wrong with the word "P{ r}erov" (a town in the Czech Republic). The accented `r' should be a special character, starting at brace-depth zero. If the original string were instead {foo bar}Herr M"uller went from P{ r}erov to {AA}rhus then the purified result would be more sensible: barHerr Muller went from Prerov to Aarhus Note the use of a "nonsense" special character "{foo bar}": this trick is often used to put certain text in a string solely for generating sort keys; the text is then ignored when the document is processed by TeX (as long as "foo" is defined as a no-op TeX macro). This assumes, of course, that the output is eventually processed by TeX; if not, then this trick will backfire on you. Also, "bt_purify_string()" is adequate for generating sort keys when you want to sort according to English-language conventions. To follow the conventions of other languages, though, a more sophisticated approach will be needed; hopefully, future versions of btparse will address this deficiency. bt_change_case() void bt_change_case (char transform, char * string, btshort options); Converts a string to lowercase, uppercase, or "non-book title capitalization", with special attention paid to BibTeX special characters and other brace-groups. The form of conversion is selected by the single character "transform": 'u' to convert to uppercase, 'l' for lowercase, and 't' for "title capitalization". "string" is modified in-place, and "options" is currently unused; set it to zero for future compatibility. Lowercase and uppercase conversion are obvious, with the proviso that text in braces is treated differently (explained below). Title capitalization simply means that everything is converted to lowercase, except the first letter of the first word, and words immediately following a colon or sentence-ending punctuation. For instance, Flying Squirrels: Their Peculiar Habits. Part One would be converted to Flying squirrels: Their peculiar habits. Part one Text within braces is handled as follows. First, in a "special character" (see above for definition), control sequences that constitute one of LaTeX's non-English letters are converted appropriately---e.g., when converting to lowercase, "AE" becomes "ae"). Any other control sequence in a special character (including accents) is preserved, and all text in a special character, regardless of depth and punctuation, is converted to lowercase or uppercase. (For "title capitalization," all text in a special character is converted to lowercase.) Brace groups that are not special characters are left completely untouched: neither text nor control sequences within non-special character braces are touched. For example, the string A Guide to LaTeXe: Document Preparation ... would, when "transform" is 't' (title capitalization), be converted to A guide to latexe: Document preparation ... which is probably not the desired result. A better attempt is A Guide to {LaTeXe}: Document Preparation ... which becomes A guide to {LaTeXe}: Document preparation ... However, if you go back and re-read the description of "bt_purify_string()", you'll discover that "{LaTeXe}" here is a special character, but not a non-English letter: thus, the control sequence is stripped. Thus, a sort key generated from this title would be A Guide to Document Preparation ...oops! The right solution (and this applies to any title with a TeX command that becomes actual text) is to bury the control sequence at brace-depth two: A Guide to {{LaTeXe}}: Document Preparation ... SEE ALSO
btparse AUTHOR
Greg Ward <gward@python.net> btparse, version 0.63 2012-05-12 btparse::doc::bt_misc(3)
All times are GMT -4. The time now is 04:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy