1830827 Members
2974 Online
110017 Solutions
New Discussion

file name

 
SOLVED
Go to solution
iranzo
Frequent Advisor

file name

Hello,
How to test the numbers of
caracters in a file name ?
example: fic_1.log
9 caracters for this file.
thanks a lot.
Bonjour
5 REPLIES 5
RAC_1
Honored Contributor
Solution

Re: file name

echo "file_name|wc -c

Anil
There is no substitute to HARDWORK
curt larson_1
Honored Contributor

Re: file name

fileName="fic_1.log"
print "${fileName} has ${#fileName} characters."
Geoff Wild
Honored Contributor

Re: file name

don't even need to cat or echo the file...

For example:

wc /etc/hosts
18 94 567 /etc/hosts

or wc -c /etc/hosts
567 /etc/hosts


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
RAC_1
Honored Contributor

Re: file name

It has to be echo "file_name\c"|wc -c

Anil
There is no substitute to HARDWORK
Abdul Rahiman
Esteemed Contributor

Re: file name

Have you noticed the count with wc -c actually report 10 instead of 9 ?
Tou should use either ${#filename} or use awk as below to get the actual no. of characters.
echo $fname | awk {'print length'}

# fname=fic_1.log
# echo $fname | wc -c
10
# echo $fname | awk {'print length'}
9
# print ${#fname}
9
No unix, no fun