|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[Solved] Count amount of times of appearing of character before a word?
Hello Is there a way to calculate how many times a particular symbol appeared in a string before a particular word. Code:
Desktop/Myfiles/pet/dog/puppy So, I want to count number of occurence of"/" in this directory before the word dog lets say. Cheers, Bob |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
echo "Desktop/Myfiles/pet/dog/puppy" | awk -F\/ '{for(i=1;i<=NF;i++){if($i~/dog/)print i-1}}'
|
| The Following User Says Thank You to itkamaraj For This Useful Post: | ||
FUTURE_EINSTEIN (04-26-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Code:
echo "Desktop/Myfiles/pet/dog/puppy" | awk -F"dog" '{print split($1,a,"/")-1}' |
| The Following User Says Thank You to shamrock For This Useful Post: | ||
FUTURE_EINSTEIN (04-26-2012) | ||
|
#4
|
|||
|
|||
|
cheers!
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to count number of times each word exist in a file | shnkool | UNIX for Dummies Questions & Answers | 4 | 12-07-2011 04:54 AM |
| Count specific word or character per line | janzper | UNIX for Advanced & Expert Users | 1 | 05-27-2011 02:42 AM |
| How to format a character to look like an amount -solved | ryukishin_17 | Shell Programming and Scripting | 0 | 04-12-2010 12:13 AM |
| scripting - write a script that will count the number of times a particular word | BigTool4u2 | Shell Programming and Scripting | 3 | 06-24-2009 01:46 PM |
| Looking for a single line to count how many times one character occurs in a word... | Shingoshi | Shell Programming and Scripting | 2 | 06-12-2009 10:12 PM |
|
|