Problem with upper and lowercase in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with upper and lowercase in awk
# 1  
Old 08-15-2013
Problem with upper and lowercase in awk

My awk (GNU Awk 3.1.8 on Ubuntu 12.04) seems to ignore case.

Code:
cat file
abc
ABC
aBc
123

Code:
awk '/[a-z]/&&/[A-Z]/{print $0,"[PASS]";next}{print $0,"[FAIL]"}' file

My result:
Code:
abc [PASS]
ABC [PASS]
aBc [PASS]
123 [FAIL]

Correct result:
Code:
abc [FAIL]
ABC [FAIL]
aBc [PASS]
123 [FAIL]



Other example
Code:
cat d
a
b
C
D

Code:
awk '/[A-Z]/' d
b
C
D

This User Gave Thanks to Jotne For This Post:
# 2  
Old 08-16-2013
Interesting. gawk 3.1.5 does the same thing.
# 3  
Old 08-16-2013
Ahh, good I am not alone with this Smilie
Some other strange test

Code:
echo a | awk '/[A-Z]/'
<no output>

Code:
echo b | awk '/[A-Z]/'
b

Code:
echo aa | awk '/[A-Z]/'
<no output>

Code:
echo ab | awk '/[A-Z]/'
ab

Single small a seems to work, but nothing else, strange
# 4  
Old 08-16-2013
This is probably a locale issue. Try:
Code:
echo b | awk '/[[:upper:]]/'

# 5  
Old 08-16-2013
Thanks
[[:upper:]] [[:lower:]] seems to work correct.
But so should A-Z and a-z do also
# 6  
Old 08-16-2013
It has to do with locales as Scrutinizer mentioned:

Ranges and Locales - The GNU Awk User's Guide
This User Gave Thanks to Franklin52 For This Post:
# 7  
Old 08-16-2013
Uff, this tells me that I have to take care when handling upper/lower case issue.
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: get upper and lower bound per group

Hi all, I've data as: 22 51018157 51018157 exonic CHKB nonsynonymous SNV 22 51018204 51018204 exonic CHKB nonsynonymous SNV 22 51018428 51018428 exonic CHKB nonsynonymous SNV 22 51018814 51018814 ... (4 Replies)
Discussion started by: genome
4 Replies

2. Shell Programming and Scripting

Lower to upper..tr + awk ?

I have a file that has a pattern 2 lines, blanktwo line If encountering the first line, the 2nd line need to be converted to UPPERCASE...or...conver the 2nd line after ablank into uppercase Is there a 'tr' function in awk..(probably the best tool over sed) ? i.e. ......................... (6 Replies)
Discussion started by: stevie_velvet
6 Replies

3. Shell Programming and Scripting

How to lowercase the values in a column in awk and include a dynamic counter?

Hi, I am trying to incorporate 2 functions into my `awk` command. I want to lower case Column 2 (which is essentially the same information in Col1, except in Col1 I want to maintain the capitalization) and I want to count from 0-N that begins and ends with the start of certain markers that I... (6 Replies)
Discussion started by: owwow14
6 Replies

4. UNIX for Dummies Questions & Answers

Convert lowercase to upper case in Sparc

Hi, I need to convert the hostname to uppercase and attach it to a string. eg: $hostname output mymac Final output should be Production.MYMAC (3 Replies)
Discussion started by: mohtashims
3 Replies

5. UNIX for Dummies Questions & Answers

Change lowercase to upper case

dear all, i have file input ABCDE_Asta_Key_Park,COJ050,10.142.3.150 C_BDEFG_City_Lake,C_BIR0,10.135.3.6 C_FDGEBIR_Axaudia,C_ABIR1,10.135.3.34 I want to change lowercase in to uppercase for all strings output ABCDE_ASTA_KEY_PARK,COJ050,10.142.3.150 C_BDEFG_CITY_LAKE,C_BIR0,10.135.3.6... (5 Replies)
Discussion started by: radius
5 Replies

6. Shell Programming and Scripting

SED (or other) upper to lowercase, with first letter of first word in each sentence uppercase

The title pretty much defines the problem. I have text files that are all in caps. I would like to convert them to lowercase, but have the first letter of the first word in each sentence in uppercase. I already have SED on the server for fixing / tweaking text files, but I'm open to other... (5 Replies)
Discussion started by: dockline
5 Replies

7. Shell Programming and Scripting

Convert lowercase to upper case based on certain conditions

Hello Unix Gurus : It would be really great if a solution can be found Following is the condition on Solaris Change all the records to upper case ignore the case for records having "A2B2 " in them . how can i use nawk or any other command Following is the SAMPLE INPUT... (6 Replies)
Discussion started by: tsbiju
6 Replies

8. Shell Programming and Scripting

Uppercase/lowercase comparison of one character per line with awk??

Another frustrating scripting problem from a biologist trying to manipulate a file with several millions line. For each of the line I need to compare the uppercase A or C or G or T with the lowercase a or c or g or t. If there are more uppercases, a + should be added to a new column, otherwise a -... (10 Replies)
Discussion started by: ivpz
10 Replies

9. UNIX for Dummies Questions & Answers

replacing all 4 first upper char of every rec to lowercase ?

I have a file where some records have been updated the wrong way and need to fix it quickly since the amount can be alot. Every record where any of the first 4 characters are in upper case need to be changed to lowercase. Records can have '#' in position-1 for comments. These musn't be... (2 Replies)
Discussion started by: Browser_ice
2 Replies

10. Shell Programming and Scripting

after i convert upper case to lowercase

If user chosen to tolower then it should convert file name to lower or vice versa. when file names converted it should put into appropriate subdirectories. e.g when files converted it then seperate them out with file etension where it will seperate them out . such as file.pdf, phone.doc both... (1 Reply)
Discussion started by: Alex20
1 Replies
Login or Register to Ask a Question