Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

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


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

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

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

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

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

Rep: Reputation: 70
Have you looked here?
Old 09-22-2008, 10:11 AM   #4
LQ Newbie
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0

Sorry I'll use the link first next time


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:19 AM.

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