[Solved] Count amount of times of appearing of character before a word?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Count amount of times of appearing of character before a word?
# 1  
Old 04-26-2012
[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
# 2  
Old 04-26-2012
echo "Desktop/Myfiles/pet/dog/puppy" | awk -F\/ '{for(i=1;i<=NF;i++){if($i~/dog/)print i-1}}'
This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 04-26-2012
Code:
echo "Desktop/Myfiles/pet/dog/puppy" | awk -F"dog" '{print split($1,a,"/")-1}'

This User Gave Thanks to shamrock For This Post:
# 4  
Old 04-26-2012
cheers!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Awk: count occurrence of each character for every field

Hi, let's say an input looks like: A|C|C|D A|C|I|E A|B|I|C A|T|I|B as the title of the thread explains, I am trying to get something like: 1|A=4 2|C=2|B=1|T=1 3|I=3|C=1 4|D=1|E=1|C=1|B=1 i.e. a count of every character in each field (first column of output) independently, sorted... (4 Replies)
Discussion started by: beca123456
4 Replies

2. Shell Programming and Scripting

Count same word which has come many times in single lines & pars

can i get a simple script for , Count same word which has come many times in single lines & pars Eg file would be == "Thanks heman thanks thanks Thanks heman thanks man" So resullt should be Thanks = 5 heman=2 man = 1 thanks in advance :) Please use code tags for code and... (1 Reply)
Discussion started by: heman96
1 Replies

3. UNIX for Dummies Questions & Answers

How do I count how many times a specific word appear in a file (ksh)?

Hi Please can you help how do I count the number of specific characters or words that appear in a file? (8 Replies)
Discussion started by: fretagi
8 Replies

4. UNIX for Dummies Questions & Answers

how to count number of times each word exist in a file

I'm trying to count the number of times each word in the file exist for example if the file has: today I have a lot to write, but I will not go for it. The main thing is that today I am looking for a way to get each word in this file with a word count after it specifying that this word has... (4 Replies)
Discussion started by: shnkool
4 Replies

5. UNIX for Advanced & Expert Users

Count specific word or character per line

Hi, I need help regarding counting specific word or character per line and validate it against a specific number i.e 10. And if number of character equals the specific number then that line will be part of the output. Specific number = 6 Specific word or char = || Sample data:... (1 Reply)
Discussion started by: janzper
1 Replies

6. Shell Programming and Scripting

How to format a character to look like an amount -solved

Hi All, I want to format the retrieved varchar2 value in the database to $9,999,999,990.00 but remained as a character value. Is it possible? Example: 378273.23 to $378,273.23 below is the code i want to implement: sqlplus -s ${USERNAME}/${PASSWORD}@${ORACLE_SID} << END1 >> $LOGFILE... (0 Replies)
Discussion started by: ryukishin_17
0 Replies

7. Shell Programming and Scripting

scripting - write a script that will count the number of times a particular word

hello everyone, I'm trying to learn some scripts but i cant get my head around two of them. 1. how can i write a script that will count the number of times a particular word is used in file? 2. how can i make a script that will take me to a web page from unix? if anyone could help it... (3 Replies)
Discussion started by: BigTool4u2
3 Replies

8. Shell Programming and Scripting

Looking for a single line to count how many times one character occurs in a word...

I've been looking on the internet, and haven't found anything simple enough to use in my code. All I want to do is count how many times "-" occurs in a string of characters (as a package name). It seems it should be very simple, and shouldn't require more than one line to accomplish. And this is... (2 Replies)
Discussion started by: Shingoshi
2 Replies

9. UNIX for Dummies Questions & Answers

count amount of accounts?

Hi, I am relatively new to Unix and trying to understand as much as I can. I would like to know if it's possible to count the total number of Unix accounts? If so, can the count be done from any working directory or does it have to be specific to where the accounts are based? Thanks! (4 Replies)
Discussion started by: Trogan
4 Replies

10. Shell Programming and Scripting

sed X amount of times - X is dynamic

I'm trying to make a bash shell script that will allow a user to modify another file based on input they give. Maybe someone can see what I'm doing wrong here. I'm still pretty new at this... Let's say my temp file contains this: 0 1 HELLO 3 4 And here's the code: old=(0 1 3 4) new=(zero... (2 Replies)
Discussion started by: Loriel
2 Replies
Login or Register to Ask a Question