Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use awk to convert all the lower-case letters into upper-case?

Tags:

linux

bash

awk

I have a file mixed with lower-case letters and upper-case letters, can I use awk to convert all the letters in that file into upper-case?

like image 253
Yishu Fang Avatar asked Dec 24 '12 13:12

Yishu Fang


People also ask

Which command can be used to convert lowercase to uppercase?

You can use `tr` command in the following way also to convert any string from lowercase to uppercase.

How do you change to uppercase in Unix?

The ^ operator converts to uppercase, while , converts to lowercase. If you double-up the operators, ie, ^^ or ,, , it applies to the whole string; otherwise, it applies only to the first letter (that isn't absolutely correct - see "Advanced Usage" below - but for most uses, it's an adequate description).

How do I convert a string to uppercase in Linux?

'^' symbol is used to convert the first character of any string to uppercase and '^^' symbol is used to convert the whole string to the uppercase. ',' symbol is used to convert the first character of the string to lowercase and ',,' symbol is used to convert the whole string to the lowercase.


2 Answers

Try this:

awk '{ print toupper($0) }' <<< "your string"

Using a file:

awk '{ print toupper($0) }' yourfile.txt
like image 143
Rubens Avatar answered Oct 12 '22 23:10

Rubens


You can use awk, but tr is the better tool:

tr a-z A-Z < input

or

tr [:lower:] [:upper:] < input
like image 27
William Pursell Avatar answered Oct 13 '22 00:10

William Pursell