06-04-2009
There are actually lots of previous threads for the counting part.
As for counting the replacements, count before, replace, count after the difference is the number you want.
You should see other relevant threads at the top or bottom of this page ( I can't remember which ) and at least one will have something you can use.
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
How can I print a '-' on the same line within awk, say 50 times, without actually typing '-' 50 times?
Cheers (3 Replies)
Discussion started by: dbrundrett
3 Replies
2. Shell Programming and Scripting
Hi,
I need to count the number of times a script is accessed from within the script. Is it possible ?
Example: I have a script called lo.sh and i execute the script for the first time, then the counter variable declared inside the lo.sh should increment by 1. For every execution the... (1 Reply)
Discussion started by: pathanjalireddy
1 Replies
3. UNIX for Advanced & Expert Users
Hi All,
I have a file of the format :
idsfskjvfdznvdfjvh
ierwjfkncmvlkmc
xszkmdvnosndzjndf
weuhrndzierfncv
rndsjnsllshens
iernzkfndslkdhf
zkinewfinfvlkmvd
I wish to count the occurrences of character 'z' in the file.
I also need to find out the position of 'z' in various lines.
and... (3 Replies)
Discussion started by: rochitsharma
3 Replies
4. UNIX for Dummies Questions & Answers
Hi,
I have the following data in a flat file:
abcd_efgh_ijkl_20080522.dat|20080602222508|1357
abcd_efgh_ijkl_20080522.dat|20080602222508|1357
abcd_efgh_ijkl_20080522.dat|20080602222508|1357
I need to check the no. of occurence of "|" (pipe) on each line and the output should look like below:... (4 Replies)
Discussion started by: hey_mak
4 Replies
5. Shell Programming and Scripting
i should use this script runs how many times before ?
how can i do_? (3 Replies)
Discussion started by: utoptas
3 Replies
6. Shell Programming and Scripting
hi,
Is it possible to print a particular character n number of times in a line?
for example.
i am print the following line using echo command..
echo "files successfully moved"
i want to count the number of characters that are been displayed. i am doin it using
echo "files... (8 Replies)
Discussion started by: Little
8 Replies
7. Homework & Coursework Questions
1. The problem statement, all variables and given/known data:
Develop a shell script that accepts a phrase and counts the number of times that it is repeated in a specific website.
Note: Im not sure if it's the whole website, or just a specific page but im guessing its thewhole website.
... (2 Replies)
Discussion started by: Zakerii
2 Replies
8. Shell Programming and Scripting
data.txt
{
"auth_type": "role",
"default_attributes": {
"sudoers": {
i need to know how manyspaces are before an actual character in each line of a file.
for example. in the above data.txt,
There are 0 spaces leading up to {
There are 4 spaces leading up to the... (7 Replies)
Discussion started by: SkySmart
7 Replies
9. Shell Programming and Scripting
I need to figure out how many times a location (columns 1 and 2) is present within a group of files. I figured using a combination of 'while read' and 'grep' I could count the number of instances but its not working for me.
cat file.txt | while read line
do
grep $line *08-new.txt | wc -l... (6 Replies)
Discussion started by: ncwxpanther
6 Replies
LEARN ABOUT MOJAVE
dispatch_semaphore_wait
dispatch_semaphore_create(3) BSD Library Functions Manual dispatch_semaphore_create(3)
NAME
dispatch_semaphore_create, dispatch_semaphore_signal, dispatch_semaphore_wait -- synchronized counting semaphore
SYNOPSIS
#include <dispatch/dispatch.h>
dispatch_semaphore_t
dispatch_semaphore_create(long count);
long
dispatch_semaphore_signal(dispatch_semaphore_t semaphore);
long
dispatch_semaphore_wait(dispatch_semaphore_t semaphore, dispatch_time_t timeout);
DESCRIPTION
Dispatch semaphores are used to synchronize threads.
The dispatch_semaphore_wait() function decrements the semaphore. If the resulting value is less than zero, it waits for a signal from a
thread that increments the semaphore by calling dispatch_semaphore_signal() before returning. The timeout parameter is creatable with the
dispatch_time(3) or dispatch_walltime(3) functions.
The dispatch_semaphore_signal() function increments the counting semaphore. If the previous value was less than zero, it wakes one of the
threads that are waiting in dispatch_semaphore_wait() before returning.
COMPLETION SYNCHRONIZATION
If the count parameter is equal to zero, then the semaphore is useful for synchronizing completion of work. For example:
sema = dispatch_semaphore_create(0);
dispatch_async(queue, ^{
foo();
dispatch_semaphore_signal(sema);
});
bar();
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
FINITE RESOURCE POOL
If the count parameter is greater than zero, then the semaphore is useful for managing a finite pool of resources. For example, a library
that wants to limit Unix descriptor usage:
sema = dispatch_semaphore_create(getdtablesize() / 4);
At each Unix FD allocation:
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
fd = open("/etc/services", O_RDONLY);
When each FD is closed:
close(fd);
dispatch_semaphore_signal(sema);
RETURN VALUES
The dispatch_semaphore_create() function returns NULL if no memory is available or if the count parameter is less than zero.
The dispatch_semaphore_signal() function returns non-zero when a thread is woken. Otherwise, zero is returned.
The dispatch_semaphore_wait() function returns zero upon success and non-zero after the timeout expires. If the timeout is DISPATCH_TIME_FOR-
EVER, then dispatch_semaphore_wait() waits forever and always returns zero.
MEMORY MODEL
Dispatch semaphores are retained and released via calls to dispatch_retain() and dispatch_release().
CAVEATS
Unbalanced dispatch semaphores cannot be released. For a given semaphore, calls to dispatch_semaphore_signal() and dispatch_semaphore_wait()
must be balanced before dispatch_release() is called on it.
SEE ALSO
dispatch(3), dispatch_object(3)
Darwin May 1, 2009 Darwin