Sponsored Content
Full Discussion: Random Line
Top Forums Shell Programming and Scripting Random Line Post 32236 by LivinFree on Wednesday 20th of November 2002 05:15:36 PM
Old 11-20-2002
Code:
# ============= excuse.web ==============
if test -f 'excuse.web' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'excuse.web' '(file already exists)'
else
  $echo 'x -' extracting 'excuse.web' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'excuse.web' &&
#! /bin/ksh
X
fil1_len=$(wc -l < ex1_lst)
X linenum=$((RANDOM%fil1_len))
X var1=$(sed -n "${linenum}p" ex1_lst)
X
fil2_len=$(wc -l < ex2_lst)
X linenum=$((RANDOM%fil2_len))
X var2=$(sed -n "${linenum}p" ex2_lst)
X
((RANDOM%2)) || {
X  fil3_len=$(wc -l < ex2_lst)
X  linenum=$((RANDOM%fil3_len))
X  var3=$(sed -n "${linenum}p" ex2_lst)
X  [[ $var3 == $var2 ]] && var3=""
X }
X
fil4_len=$(wc -l < ex3_lst)
X linenum=$((RANDOM%fil4_len))
X var4=$(sed -n "${linenum}p" ex3_lst)
X
fil5_len=$(wc -l < ex4_lst)
X linenum=$((RANDOM%fil5_len))
X var5=$(sed -n "${linenum}p" ex4_lst)
X
typeset -L1 -l comp=$var1
X [[ $comp == ?([aeiou]) ]] && { conj=an; } || { conj=a; }
X
print "<BR>
**************************************<BR>
**************************************<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Excuse Calendar - $(date +%D)<BR>    
**************************************<BR>
**************************************<BR>
<BR>
The problem appears to be caused by $conj $var1 $var2 $var3 $var4 $var5 <BR>
<BR>"
X
SHAR_EOF
  (set 20 02 11 14 11 57 43 'excuse.web'; eval "$shar_touch") &&
  chmod 0700 'excuse.web' ||
  $echo 'restore of' 'excuse.web' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'excuse.web:' 'MD5 check failed'
003805135a7f3654adb34d0a27edb4d0  excuse.web
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'excuse.web'`"
    test 1002 -eq "$shar_count" ||
    $echo 'excuse.web:' 'original size' '1002,' 'current size' "$shar_count!"
  fi
fi
# ============= serve_exc ==============
if test -f 'serve_exc' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'serve_exc' '(file already exists)'
else
  $echo 'x -' extracting 'serve_exc' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'serve_exc' &&
#! /bin/ksh
X
while :
do
X    nc -l -p 8080 |& 
X    exec 3<&p 4>&p
X    
X    while read -u3 line
X    do
X        [[ $line = ?(\r) ]] && break
X    done
X    
X    file=html.$$
X    print "<HTML><HEAD><TITLE>BOfH Excuse Calendar</TITLE></HEAD>" >$file
X    print "<BODY>" >>$file
X    ./excuse.web >>$file 
X    print "</BODY></HTML>" >>$file
X 
X	print -u4 "HTTP/1.0 200 OK\r"
X	print -u4 "Server: /bin/ksh\r"
X        print -u4 Content-Length: $(wc -c < $file)"\r"
X        print -u4 "\r"
X        cat "$file" >&4
X
X    rm -f $file
X    exec 3>&- 4>&-
X    kill -1 $! >/dev/null 2>&1
done
X
SHAR_EOF
  (set 20 02 11 14 15 20 36 'serve_exc'; eval "$shar_touch") &&
  chmod 0700 'serve_exc' ||
  $echo 'restore of' 'serve_exc' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'serve_exc:' 'MD5 check failed'
9775ce6be608ea64537597c30cce22ba  serve_exc
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'serve_exc'`"
    test 571 -eq "$shar_count" ||
    $echo 'serve_exc:' 'original size' '571,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh26541
exit 0

Make sure to append this one to the above without any spaces inbetween...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Random

My problem is as follow and i hope you can help: I currently have this function: stored_word() { number=$RANDOM let "number %= 21" case $number in 0 ) echo "energy" ;; 1 ) echo "touch" ;; 2 ) echo "climbing" ;; 3 ) echo "declare" ;; 4 ) echo "marry" ;; 5 ) echo "relax" ... (8 Replies)
Discussion started by: keyvan
8 Replies

2. Shell Programming and Scripting

$random

I need to use the $RANDOM command to get a line from a list of lines in a file randomly. file is help go three house film how do i randomly get one word without looking into the file? (6 Replies)
Discussion started by: relle
6 Replies

3. Shell Programming and Scripting

Read random line from a text file

I have a text file with hundreds of lines, i wish to run a script and reads a random line to pass it to another command line such as: for line in `cat file |grep random line`; do echo $line |mail my@example.com ; done thank you (6 Replies)
Discussion started by: Bashar
6 Replies

4. 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

5. Shell Programming and Scripting

Replace 2nd column for each line in a csv file with fixed string+random number

Hi experts, My csv file looks like this U;cake;michael;temp;;;; U;bread;john;temp;;;; U;cocktails;sarah;temp;;;; I'd like to change the value fo 2nd column to cf+random number , which will look maybe something like this U;cf20187;michael;temp;;;; U;cf8926;john;temp;;;;... (7 Replies)
Discussion started by: tententen
7 Replies

6. Shell Programming and Scripting

Parse large file on line count (random lines)

I have a file that needs to be parsed into multiple files every time there line contains a number 1. the problem i face is the lines are random and the file size is random. an example is that on line 4, 65, 187, 202 & 209 are number 1's so there has to be file breaks between all those to create 4... (6 Replies)
Discussion started by: darbs121
6 Replies

7. 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

8. 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

9. Shell Programming and Scripting

How to insert random numbers into each line?

I have a file contains thousands of lines. I want to insert n random numbers into each line at specific position. Like this: 0 22…… 1 33…… …… …… I want to insert 3 random numbers from position 2 to 4 into each line. 0 325 22…… 1 685 33…… …… …… Please use CODE tags when... (8 Replies)
Discussion started by: hhdzhu
8 Replies

10. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
All times are GMT -4. The time now is 07:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy