We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,263 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

shell script

i need to print the file names of all files having .txt extension of a given directory after converting to uppercase letters. The input (directory name) should be given as command line argument. The script will also check whether sufficient arguments are passed or not and whether the argument is a directory or not

i tried using this code

if [ -f $filename ]
tr "[a-z]" "[A-Z]" <$filename

but i dint get output

3
Contributors
3
Replies
2 Weeks
Discussion Span
1 Year Ago
Last Updated
4
Views
vignesh viki
Newbie Poster
5 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

What did you get?

L7Sqr
Practically a Posting Shark
851 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7

Hi,

Is this answer for your question?

---------------------------------------------------------
#!/bin/sh

if [ -d $1 ]
then
echo "Yes this is a directory"
else
echo "No this is not a directory"
fi

cd $1
echo "dir is: `pwd`"

FILES=`ls *.txt`

for i in $FILES
do
echo $i | tr '[:lower:]' '[:upper:]'
done
-----------------------------------------------------------------------------

correct me if my understanding is wrong?

BR/ KMat

i need to print the file names of all files having .txt extension of a given directory after converting to uppercase letters. The input (directory name) should be given as command line argument. The script will also check whether sufficient arguments are passed or not and whether the argument is a directory or not

i tried using this code

if [ -f $filename ]
tr "[a-z]" "[A-Z]" <$filename

but i dint get output

KMat
Newbie Poster
10 posts since Dec 2011
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0

if [ -d $1 ]
then
echo "Yes this is a directory"
else
echo "No this is not a directory"
fi

cd $1
echo "dir is: `pwd`"

KMat, what happens when $1 is not a directory? What do you think will happen when you do cd $1 ?

L7Sqr
Practically a Posting Shark
851 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1181 seconds using 2.66MB