Shell Script To Translate All Characters In a File To Lowercase

in Categories File-management last updated September 16, 2008

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]'

Share this on:

3 comment

  1. 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

    Have a question? Post it on our forum!