Sponsored Content
Top Forums Shell Programming and Scripting Grab exactly one byte from a FIFO, at random intervals Post 302747903 by Yoda on Sunday 23rd of December 2012 04:50:11 PM
Old 12-23-2012
Here is the code:
Code:
#!/bin/bash

MY_INPUT=INPUT
MY_FIFO=FIFO

(
tail -f ${MY_INPUT} | while IFS= read -n 1 CHAR ; do
        printf "${CHAR}" > ${MY_FIFO}
done
) &
READPID=$!

PROMPT=n
while [ "${PROMPT}" != "q" ]
do
        printf 'y: print next byte\nn: don'"'"'t print next byte\nq: quit\n'
        read -n 1 PROMPT
        printf '\n'
        if [ "${PROMPT}" = "y" ]
        then
# This is 'grab1byte':
                echo The input byte is:
                xxd -cols 1 ${MY_FIFO} | sed 's/^.*: //'
        fi
done

kill $READPID

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date Intervals

I posted a question on date intervals about a month back asking about how I could be able to go about a user entering the starting year/month/day and an ending year/month/day and then the script automatically cycling through each day of each month of each year that the user has specified. I... (7 Replies)
Discussion started by: yongho
7 Replies

2. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

3. Shell Programming and Scripting

Remove a byte(Last byte from the last line)

Hi All Can anyone please suggest me how to remove the last byte from a falt file .This is from the last line's last BYTE. Please suggest me something. Thank's and regards Vinay (1 Reply)
Discussion started by: vinayrao
1 Replies

4. Shell Programming and Scripting

Divide numbers into intervals

divide input values into specified number (-100 or -200) according to the key (a1 or a2 ....) For ex: if we give -100 in the command line it would create 100 number intervals (1-100, 100-200, 200-300) untill it covers the value 300 in a1. Note: It should work the same even with huge numbers... (3 Replies)
Discussion started by: ruby_sgp
3 Replies

5. Ubuntu

expect script for random password and random commands

Hi I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue: I want expect script for random passwords and random commands generation. please can anyone help me? Many Thanks in advance (0 Replies)
Discussion started by: vanid
0 Replies

6. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies

7. UNIX for Dummies Questions & Answers

A crude random byte generator...

There was an upload recently on generating a pseudo-random file when /dev/random does NOT exist. This does not need /dev/random, /dev/urandom or $RANDOM either... (I assume $RANDOM relies on the /dev/random device in some way.) This code uses hexdump just because I like hexdump for ease of... (2 Replies)
Discussion started by: wisecracker
2 Replies

8. UNIX for Dummies Questions & Answers

Building intervals

Hi all, I hope you can help me with the following question: I have multiple tables like this: Chr Start End Zygosity Gene chr1 153233510 153233510 het LOR chr1 153233615 153233615 hom LOR chr1 153233701 153233701 hom LOR chr1 ... (5 Replies)
Discussion started by: lsantome
5 Replies

9. UNIX for Dummies Questions & Answers

Changing a special line and Byte in a random file

Hello I created 3 files by: dd if=/dev/urandom bs=1024 count=1000000 of=./testfile1 dd if=/dev/urandom bs=1024 count=5000000 of=./testfile2 dd if=/dev/urandom bs=1024 count=10000000 of=./testfile3 Now I want to know how to make a change in a specific byte and/or line of theses files? (2 Replies)
Discussion started by: frhling
2 Replies

10. UNIX for Dummies Questions & Answers

Gap length between intervals

hi all, I wish to calculate the length between intervals whose are defined by a starting and an end possition. The data looks like this: 1 10 23 30 45 60 70 100... The desired output should be: 13 # (23-10) 15 # (45-30) 10 # (70-60)... I donīt know how to operate with different... (2 Replies)
Discussion started by: lsantome
2 Replies
GCAP.1(1p)						User Contributed Perl Documentation						GCAP.1(1p)

NAME
gcap - Youtube closed caption downloader SYNOPSIS
gcap [-i] [-t] [-r <regexp>] [--proxy=<addr> | --no-proxy] [--help] <url> | <video_id> DESCRIPTION
gcap is a command line tool for downloading Youtube closed captions. The downloaded closed captions are saved in SubRip (srt) file format. The srt files are saved as "$videoid_$langid.srt" by default. OPTIONS
--help Print help and exit. --version Print version and exit. -q, --quiet Be quiet. -i, --interactive Open the interactive prompt which can be used to select the items. gcap selects all items by default. See also "INTERACTIVE PROMPT". -t, --title Parse video title and use it in the output filename(s) instead of video ID. The default is no. -r, --regexp=arg Cleanup video title using the specified arg regular expression. The default is "/(w|s)/g". --proxy arg Use arg for HTTP proxy, e.g. "http://foo:1234". Overrides the http_proxy environment setting. --no-proxy Disable use of HTTP proxy. Overrides both "--proxy" and http_proxy environment settings. INTERACTIVE PROMPT
Use the "--interactive" switch to open the prompt. Note that gcap uses (as of 0.1.0) the Umph::Prompt module for this. Once the prompt opens, type "help" to get a list of commands available to the prompt. EXAMPLES
gcap 0QRO3gKj3qw gcap "http://www.youtube.com/watch?v=0QRO3gKj3qw" Both yield the same results. gcap -ti 0QRO3gKj3qw Same as above two but use video title in the filename and choose which of the closed captions should be downloaded. EXIT STATUS
Exits 0 on success, otherwise 1. FILES
$HOME/.gcaprc, for example: echo "--interactive" >> ~/.gcaprc NOTES
Availability The following error message produced by gcap (or the XML::DOM module) typically indicates that the video does not have any closed captions available for it (URL omitted for brewity): Couldn't parsefile [...] with LWP: no element found at line 1, column 0, byte -1 at [...]/XML/Parser.pm [...] http_proxy gcap depends on XML::DOM which uses LWP::UserAgent to download the data. Note that LWP::UserAgent reads http_proxy environment setting. e.g.: env http_proxy=http://foo:1234 gcap video_id WWW
<http://gcap.googlecode.com/> <http://repo.or.cz/w/gcap.git> AUTHOR
Toni Gundogdu <legatvs at sign cpan org> perl v5.12.4 2011-11-15 GCAP.1(1p)
All times are GMT -4. The time now is 03:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy