Sponsored Content
Top Forums Shell Programming and Scripting Read random line from a text file Post 302355875 by Bashar on Thursday 24th of September 2009 02:50:39 AM
Old 09-24-2009
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:
Code:
for line in `cat file |grep random line`; do echo $line |mail my@example.com ; done

thank you
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to read and write a random row from a file?

Lets say I have a file abc.txt and it has about 35 million rows. I would like to take a sample of 100 random rows from that file for my testing purpose and write it to a file say test.txt. How do I do this operation? Thanks, Sashank (9 Replies)
Discussion started by: sashankkrk
9 Replies

2. Shell Programming and Scripting

Read from text file misses first line

Hi! I need to read in the first line from a text file (which will only ever have one line in it), so I tried this.... while read line do echo $line done < $file But this wasn't returning anything. So I tired a different file, which had multiple lines of text in it, and it returned... (2 Replies)
Discussion started by: davewg
2 Replies

3. Shell Programming and Scripting

Script does not read the last line of text file

Hello, I have got a script that reads a text file, and have got three problems that I an struggling with. 1. The script does not read the last line in the text file 2. within the second 'elif' within the script I included a 'break' - the script runs successfully (except for the first... (2 Replies)
Discussion started by: jermaine4ever
2 Replies

4. Shell Programming and Scripting

Read text file line by line

Hi everyone, I am writing a BASH shell script that I will use to process data files. I have a text file that contains the names of the files to be processed, for example: cat filenames.txt file1 file2 file3 file4 file5 What I would like to do is set up a FOR loop within my script... (2 Replies)
Discussion started by: msb65
2 Replies

5. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

6. Shell Programming and Scripting

how read specific line in a file and write it in a new text file?

I have list of files in a directory 'dir'. Each file is of type HTML. I need to read each file and get the string which starts with 'http' and write them in a new text file. How can i do this shell scripting? file1.html <head> <url>http://www.google.com</url> </head> file2.html <head>... (6 Replies)
Discussion started by: vel4ever
6 Replies

7. Shell Programming and Scripting

How to read the first work of each line from text file?

Hi ppl. I want to read the first word of each line of a text file to a variable in a bash script. Can anyone help pls, thanks. (6 Replies)
Discussion started by: cannot
6 Replies

8. Programming

Read text from file and print each character in separate line

performing this code to read from file and print each character in separate line works well with ASCII encoded text void preprocess_file (FILE *fp) { int cc; for (;;) { cc = getc (fp); if (cc == EOF) break; printf ("%c\n", cc); } } int main(int... (1 Reply)
Discussion started by: khaled79
1 Replies

9. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

10. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies
randtype(1)						      General Commands Manual						       randtype(1)

NAME
randtype - Output characters or lines at random intervals SYNOPSIS
randtype [ -l ] [ -d ,|.<string> [ -k ] ] [ -t <ms,mult> ] [ -w <string> [ -c ms,mult ] ] [ -r s1,s2[:...] ] [ -n <string> ] [ -q <int> ] [ -m <int> ] [ file ... ] DESCRIPTION
randtype reads input from either standard input or from a file and outputs each character or line at random intervals. If multiple files are specified, each is read in sequence. OPTIONS
randtype recognizes the following command line options: -c ms,mult For optional use with the -w option, this has the same microsecond and multiplier value format as the -t option. The default for this option is specified at compile time. -d string Output everything before (left) or after (right) the specified string immediately. The string must begin with either ',' or '.' which specifies the direction, left or right, respectively. -h Print a summary of the command line options and exit. -k Suppress output of the string specified by the dump string option. -l Output lines rather than characters. Only the -t and -q options are valid when using this option, all other options are ignored. -m int Generate random mistakes. The int value is how many times to compare and match the next character and a randomly generated charac- ter. -n chars Output the specified characters immediately with no random waiting. -r s1,s2[:...] Replace the string s1 with string s2. You can specify multiple replacements by separating them with a ':'. -q int Quit the program after this many seconds. -t ms,mult This option refines the random delay of output. The value of the argument is separated by a comma with the first argument being a microsecond and the second being a multiplier of a random number between 0 and the microsecond. A character-per-second effect can, for example, be made by setting the microsecond to 0 and the multiplier to 1000000. The default for this option is specified at com- pile time. -v Display version information and exit. -w chars The inverse of the -n option; this option waits on the specified characters. Use the -c option to refine the random delay of output. EXAMPLE
randtype -t 13,16000 -d ",*MAGIC*" -k -n '0ou' filename SEE ALSO
random(3), srandom(3), alarm(2), select(2) AUTHOR
This program was created by bjk <bjk@arbornet.org> and released under the terms of the GNU General Public License version 2 or later. randtype randtype(1)
All times are GMT -4. The time now is 06:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy