LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-22-2008, 10:00 AM   #1
basildon
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Rep: Reputation: 0
Bash: Counting the number of character occurences in a variable


Hi

I have a file of variables ($var) each containing a directory location.

I would like to count the number of / characters in each variable

Thanks
 
Old 09-22-2008, 10:04 AM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 31
Look at post #4 from here.

Basically:
Code:
echo $var | tr -dc '/' | wc -c
Hope it helps.
 
Old 09-22-2008, 10:04 AM   #3
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
Have you looked here?
http://www.linuxquestions.org/questi...5/#post3165846
 
Old 09-22-2008, 10:11 AM   #4
basildon
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks

Sorry I'll use the link first next time
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scripting : printing variable with the number within $i amdGTintel Programming 2 01-18-2007 01:30 AM
[Bash] New line character in variable michael_hk Linux - Newbie 4 06-15-2006 02:13 PM
Counting number of occurences of a certain chacter in string java linuxmandrake Programming 4 04-27-2006 11:10 PM
C++ STL count() number of substring occurences... nyk Programming 4 06-25-2004 07:12 AM
[Bash] Find occurences in a file, then change them fr0st Linux - General 2 04-05-2004 09:11 AM


All times are GMT -5. The time now is 07:52 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration