There are two things that leap immediately to mind...
tail -f
or
multitail
line
Step 2
There are two things that leap immediately to mind...
tail -f
or
multitail
This solution will avoid writing repeatedly to disk, and even though it in worst case takes a second instead of the desired less than half a second, I found it to be fast enough after trying it. So, here are the two scripts I use:
./detect:
while true; do
arecord -d 1 /dev/shm/tmp_rec.wav ; sox -t .wav /dev/shm/tmp_rec.wav -n stat 2>\
&1 | grep "Maximum amplitude" | cut -d ':' -f 2 | ./check.py
if [ $? -eq 0 ] ; then
amixer set Master 0
else
amixer set Master 80
fi
done
./check.py:
#!/usr/bin/env python
import sys
number = 0.0
thing="NO"
line = sys.stdin.readline()
thing = line.strip()
number = float(thing)
if number < 0.15:
raise Exception,"Below threshold"
Hardly elegant, but it works.
Note: If you want a more gradual thing, add something like this:
for i in `seq 0 80 | tac`; do
amixer set Master $i
done
for muting and
for i in `seq 0 80`; do
amixer set Master $i
done
for unmuting.
No, operating systems like Linux, and it's filesystems, don't make provision for removing data from the start of a file. In other words, the start point of storage for a file is fixed.
Removing lines from the start of a file is usually accomplished by writing the remaining data to a new file and deleting the old. If a program has the old file open for writing, that file's deletion is postponed until the application closes the file.
Your question is a bit unclear. Do you want to connect to a wireless network? There's a standard tool for this on Ubuntu, the Network Manager. See e.g. https://help.ubuntu.com/8.04/internet/C/wireless-connecting.html for details.
If you cannot use X (which Network Manager needs), you should
also be able to set up networking manually, the way Debian does
it. Debian offers several mechanisms to do this. The easiest is
to just put a block for your interface into
/etc/network/interfaces
. Sample block for a WLAN
network interface:
iface wlan0 inet dhcp
wpa-ssid MyNetWork
# plaintext passphrase
wpa-psk plaintextsecret
Using the config above, you can then type (as root)
ifup wlan0
to activate the interface (ifdown wlan0
to
deactivate).
See http://wiki.debian.org/WiFi for more information.
To compare files side-by-side, my favorite tool is Notepad++.
After installing it, on the toolbar click Plugins>Plugin Manager>Available, and check Compare and Install.
After restarting Notepad++, open up the two files (they will open in different tabs), and in the toolbar go to Plugins>Compare>Compare.
There are multiple tweaks you can do, but comparing files looks something like this:
where white text is unchanged, red is removed, green is added, and the sidebar shows an overview of those changes in the two files.
I think the missing ingredient is how your display_orders script works (ie without specifics the problem can't be properly solved).
"expect" is definately the "best" solution.
I did, however, come up with a quick-and-nasty hack which might (but probably won't) work for you. If the problem is a slight delay in inputs confusing the display_orders script, and its not time sensitive, you could blindly wait a short period between responses -
(
echo $BROKERA
sleep 1
echo $Size
sleep 1
echo $Side
sleep 1
echo $Symbol
) | display_orders | mailx -s 'Daily OATS Check' some@email.com
of-course the sleep 1 can be changed to a longer value and
$BROKERA
, $SIZE
, $Side
and
$Symbol
are already set. Its a cludge because it has
no feedback to check if it's answering the right question, and
its slow and generally yuk, but it probably does not have any
special software prerequisites over and above what is on most
systems)
#!/bin/bash
while read filename; do
touch $filename
done < filename.txt
This will iterate over each line of filename.txt and create empty file with name in the current line.
I don't think there's anything built in, but you can pipe together a bit of a hack:
find . -ls | sort -k5
This works because on my installation the fifth column
(-k5
) of output from find
is the
username. Clearly this isn't portable.
Your question cannot really be reasonably answered. You're kind of asking the wrong question here.
There is no constant number of characters per line. A line, in
the general, technical sense, can be an arbitrarily long sequence
of characters that ends with a newline character \n
.
If that character just doesn't occur, the line can become
extremely long. It really depends on the
contents of what you write. It's not like in a word
processor (or on this web site), where line breaks occur
automatically, and the possible line length depends on font size,
or page orientation.
In source code, this is also coupled with the difficulty of determining what exactly a line of code is. Do source code comments, that aren't actually code, i.e. processing instructions, count? Do empty lines (lines with only whitespace) count? For source code, there's a metric called Source Lines of Code, or SLOC. This article has some more information about it.
In a linked article, the H states:
It's worth noting that these figures do include the comments, blank lines, documentation, scripts and userland tools included with the kernel (
find . -type f -not -regex '\./\.git.*' | xargs cat | wc -l
).
So it's really the number of newline characters, including
comments, empty lines, etc. of all files excluding the revision
control metadata (git) files. This measures the physical
lines (counting the \n
characters), and really
depends on things like source code formatting.
^ This looks like a -really- good site for what you're looking for.
The utility line copies one line (up to a newline) from standard input to standard output. It always prints at least a newline and returns an exit status of 1 on EOF or read error.
The line command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
read