Shell Script To Translate All Characters In a File To Lowercase

by Vivek Gite [Last updated: September 16, 2008]

in File-management

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]'
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our email newsletter to make sure you don't miss a single tip/tricks.

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , ,

Previous post: Shell Script To Rename File Name To Lowercase

Next post: Shell Script To Combine Any Three Text Files Into a Single File