08-11-2011
Thanks zaxxon and alister,
I tried the code, in the output I could see the last line is gone.. Also I think in this logic we are counting the lines in the file and then replacing it. Please correct me if I'm wrong.
Also I have the count, I don't want to traverse to count the lines. but I need to replace the record count with entirely different number. I mean the count which is in the last line, I hv to replace exactly that without counting. Please suggest.
thanks in advance.
9 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hii to all..
I have a file stud.lst
bash-3.1$ cat stud.lst
NO NMAE DOB 10 +2 BE AVG
075 syam saksena 12/12/55 500 398 550 48.26
099 sachin 11/05/47 450 500 600 51.66
300 mohan kumar 19/04/43 500 600 700 60.00
100 john 12/12/52 800 750 700 75.00
125... (2 Replies)
Discussion started by: krishnampkkm
2 Replies
2. UNIX for Dummies Questions & Answers
Hi. I have a basic script in python that outputs like this..
$ ./test.py
1%
2%
3%
4%
5%
6%
7%
8%
9%
10%
...
But how can I make it so the output stays in 1 line?
So it would look something like this..
$ ./test.py
10% (1 Reply)
Discussion started by: cbreiny
1 Replies
3. Shell Programming and Scripting
Dear all,
I'm trying to write a script where:
A file contains more or less 2000 lines. To some of those lines, in a specific position, let's say 89-92 there are spaces. So, this script should find these spaces on specific position and update a value (from 2 to 1) to another position of the... (4 Replies)
Discussion started by: paniklas
4 Replies
4. Shell Programming and Scripting
Hi everyone
i need one help don't know whether it is simple or difficult but not able to solve it.
here is the problem
suppose my code is
time_def=3
r=0
while ]
do
echo "time left is $time_def "
((time_def=time_def-1))
done
and the output is
time left is 3
time left... (6 Replies)
Discussion started by: aishsimplesweet
6 Replies
5. Shell Programming and Scripting
Hi,
I have got the below requirement. please suggest.
I have a file like,
Processing Item is:
/data/ing/cfg2/abc.txt
/data/ing/cfg3/bgc.txt
Processing Item is:
/data/cmd/for2/ght.txt
/data/kernal/config.klgt.txt
I want to process the above file to get the output file like,
... (5 Replies)
Discussion started by: rbalaj16
5 Replies
6. Shell Programming and Scripting
my requirement is,
consider a file output
cat output
blah sdjfhjkd jsdfhjksdh
sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf
hellow there
this doesnt look good
et cetc etc
etcetera
i want to replace a line of line number 4 ("this doesnt look good") with some other line
... (3 Replies)
Discussion started by: vivek d r
3 Replies
7. Shell Programming and Scripting
Hi all,
I have a file called "text.cpp" with the first line of "1"
afterwards I tried in Ubuntu to type the following
sed '12iasdasdasdasdsad' test.cpp > output.txt
however when I tried to see the result of output.txt
#cat output.txt
1
why is the line 12 is not updated to the... (6 Replies)
Discussion started by: peuceul
6 Replies
8. Shell Programming and Scripting
Hi,
I have a xml file that I need to modify 1 line to change some value from 2 to 10 (or any number).
Sample input:
<!-- some text here>
.
.
.
<message:test name="ryan">
<message:sample-channel charset="UTF-8" max-value="2" wait="20">
... (5 Replies)
Discussion started by: brichigo
5 Replies
9. Shell Programming and Scripting
I have a file and need to update the specific position on line two. I tried to use this solution under the post "Awk command to replace specific position characters"
But need a way to just limit to update the line 2 and not every line on the file.
awk 'function repl(s,f,t,v) { return... (1 Reply)
Discussion started by: Sandeep
1 Replies
LEARN ABOUT DEBIAN
coro::semaphore
Semaphore(3pm) User Contributed Perl Documentation Semaphore(3pm)
NAME
Coro::Semaphore - counting semaphores
SYNOPSIS
use Coro;
$sig = new Coro::Semaphore [initial value];
$sig->down; # wait for signal
# ... some other "thread"
$sig->up;
DESCRIPTION
This module implements counting semaphores. You can initialize a mutex with any level of parallel users, that is, you can intialize a
sempahore that can be "down"ed more than once until it blocks. There is no owner associated with semaphores, so one thread can "down" it
while another can "up" it.
Counting semaphores are typically used to coordinate access to resources, with the semaphore count initialized to the number of free
resources. Threads then increment the count when resources are added and decrement the count when resources are removed.
You don't have to load "Coro::Semaphore" manually, it will be loaded automatically when you "use Coro" and call the "new" constructor.
new [inital count]
Creates a new sempahore object with the given initial lock count. The default lock count is 1, which means it is unlocked by default.
Zero (or negative values) are also allowed, in which case the semaphore is locked by default.
$sem->count
Returns the current semaphore count.
$sem->adjust ($diff)
Atomically adds the amount given to the current semaphore count. If the count becomes positive, wakes up any waiters. Does not block if
the count becomes negative, however.
$sem->down
Decrement the counter, therefore "locking" the semaphore. This method waits until the semaphore is available if the counter is zero.
$sem->wait
Similar to "down", but does not actually decrement the counter. Instead, when this function returns, a following call to "down" or
"try" is guaranteed to succeed without blocking, until the next thread switch ("cede" etc.).
Note that using "wait" is much less efficient than using "down", so try to prefer "down" whenever possible.
$sem->wait ($callback)
If you pass a callback argument to "wait", it will not wait, but immediately return. The callback will be called as soon as the
semaphore becomes available (which might be instantly), and gets passed the semaphore as first argument.
The callback might "down" the semaphore exactly once, might wake up other threads, but is NOT allowed to block (switch to other
threads).
$sem->up
Unlock the semaphore again.
$sem->try
Try to "down" the semaphore. Returns true when this was possible, otherwise return false and leave the semaphore unchanged.
$sem->waiters
In scalar context, returns the number of threads waiting for this semaphore.
$guard = $sem->guard
This method calls "down" and then creates a guard object. When the guard object is destroyed it automatically calls "up".
AUTHOR
Marc Lehmann <schmorp@schmorp.de>
http://home.schmorp.de/
perl v5.14.2 2012-04-13 Semaphore(3pm)