The toupper (string) function

The toupper() function takes a single string as an argument and returns a copy of that string, with all the lowercase characters converted to uppercase. The nonalphabetic characters are left unchanged. The following example illustrates the usage of the toupper() function:

$ vi toupper1.awk

BEGIN {
str = "Linux is derived from Unix. Unix is oldest OS."
upper_case_str = toupper(str)
print "Original String : ", str
print "Uppercase String : ", upper_case_str
}

$ awk -f toupper1.awk

The output of the execution of the previous code is as follows:

Original String :  Linux is derived from Unix. Unix is oldest OS.
Uppercase String : LINUX IS DERIVED FROM UNIX. UNIX IS OLDEST OS.

Similarly, in our next example, we convert the contents of our emp.dat employee database file to uppercase using the toupper() function, as follows:

$ awk '{ printf("%s
", toupper($0)) }' emp.dat

The output of the execution of the previous code is as follows:

JACK    SINGH   9857532312  [email protected]      M   HR      2000
JANE KAUR 9837432312 [email protected] F HR 1800
EVA CHABRA 8827232115 [email protected] F LGS 2100
AMIT SHARMA 9911887766 [email protected] M LGS 2350
JULIE KAPUR 8826234556 [email protected] F OPS 2500
ANA KHANNA 9856422312 [email protected] F OPS 2700
HARI SINGH 8827255666 [email protected] M OPS 2350
VICTOR SHARMA 8826567898 [email protected] M OPS 2500
JOHN KAPUR 9911556789 [email protected] M HR 2200
BILLY CHABRA 9911664321 [email protected] M LGS 1900
SAM KHANNA 8856345512 [email protected] F LGS 2300
GINNY SINGH 9857123466 [email protected] F HR 2250
EMILY KAUR 8826175812 [email protected] F OPS 2100
AMY SHARMA 9857536898 [email protected] F OPS 2500
VINA SINGH 8811776612 [email protected] F LGS 2300
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.103.5