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.

#!/bin/bash
# Write a shell script to translate all the characters to lower case in
# a given text file.
# -------------------------------------------------------------------------
# Copyright (c) 2001 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
echo -n "Enter a text file name : "
read file
 
if [ ! -f $file ]
then
	echo "$file not a file!"
	exit 1
fi
 
cat $file | tr '[A-Z]' '[a-z]'
Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
Category List of Unix and Linux commands
File Management cat
Firewall Alpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities 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:
    #!/bin/bash
    #tarek_20307
    #exercise 3:

    case $1 in
    -i)
    count= ‘grep ^i $2 | WC -1′
    echo “The Number of LINES in The $2 That begin with the letter i IS $count”
    ;;
    -e)
    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 ”
    ;;
    esac

    • 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. Required fields are marked *

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