Shell Script To Translate All Characters In a File To Lowercase

This command uses tr command to translate all uppercase characters to lowercase characters in a file.

# Write a shell script to translate all the characters to lower case in
# a given text file.
# -------------------------------------------------------------------------
# Copyright (c) 2001 nixCraft project <>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit for more information.
# -------------------------------------------------------------------------
echo -n "Enter a text file name : "
read file
if [ ! -f $file ]
	echo "$file not a file!"
	exit 1
cat $file | tr '[A-Z]' '[a-z]'
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics via:
Category List of Unix and Linux commands
Disk space analyzers ncdu pydf
File Management cat
Firewall Alpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities NetHogs dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN Alpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Avinash Chauhan Jul 3, 2017 @ 9:44

    very nice.

  • fadi Mar 5, 2009 @ 10:19

    I have problem with this script (the program count the number of lines in the file specified by the second command-line option that begin with the letter i.) , the output is :
    erorr (can’t found ‘grep ^i $2 | WC -1’ ) , please can you help me to fix the problems

    shell script:
    #exercise 3:

    case $1 in
    count= ‘grep ^i $2 | WC -1′
    echo “The Number of LINES in The $2 That begin with the letter i IS $count”
    count=’grep ^e $2 | wc -1’
    echo “The Number of LINES in The That begin with the letter e IS”
    echo “error: this option is incorrect ”

    • Ken Feb 17, 2010 @ 22:19

      The wildcards you want to use are part of regular expression patterns. You need to use grep -e

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.