Sponsored Content
Top Forums Shell Programming and Scripting Help with AWK and RANDOM please Post 302212423 by Franklin52 on Monday 7th of July 2008 01:57:01 PM
Old 07-07-2008
This is an example how to fill an array "arr" with the value of the first field of a file and print a random element of the array.
Code:
awk '
{arr[++i]=$1}
END{srand()
element=int(rand()*i+1)
print arr[element]
}' file

Regards
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how can i isolate the random sequence of numbers using awk?

as you can see there is a delimiter after c8 "::". Awk sees the rest as fields because it doesn't recognize spaces and tabs as delimiters. So i am basically looking to isolate 20030003ba13f6cc. Can anyone help? c8::20030003ba13f6cc disk connected configured unknown (2 Replies)
Discussion started by: rcon1
2 Replies

2. Shell Programming and Scripting

doing rot13 on a field with a random number with awk

i have a several million line file like this: M:charitygeneral:water:fairbanks:charitygeneral field 2 and field 5 are the same i want to read the file and rot13 or any caesar cipher field 2 and replace the with a random number 1 - 9 anyone know how to do this? something slightly... (8 Replies)
Discussion started by: bathtub
8 Replies

3. Shell Programming and Scripting

help with ksh/awk/sed script, random # of fields

Hello all, I'm working on an attendance callout script for a school district. I need to change our current layout for the vendor. Currently the data is in the form of: studentid,period,building, Heres a sample of some made up records: 500,1,30, 500,2,30, 500,3,30, 500,6,30,... (7 Replies)
Discussion started by: axo959
7 Replies

4. Shell Programming and Scripting

choose random text between constant string.. using awk?

Hallo I have maybe a little bit advanced request.... I need to choose one random part betwen %.... so i have this.. % text1 text1 text1 text1 text1 text1 text1 text1 text1 % text2 text2 text2 text2 text2 % text3 text3 text3 tetx3 % this choose text between % awk ' /%/... (8 Replies)
Discussion started by: sandwich
8 Replies

5. Shell Programming and Scripting

Random word generation with AWK

Hi - I have a word GTTCAGAGTTCTACAGTCCGACGAT I need to extract all the possible "chunks" of 7 or above letter "words" from this. SO, my out put should be GTTCAGA TTCAGAG TCAGAGT CAGAGTTCT TCCGACGAT CAGTCCGACG etc. How can I do that with awk or any other language? I have no... (2 Replies)
Discussion started by: polsum
2 Replies

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

7. Shell Programming and Scripting

unique random numbers awk

Hi, I have a small piece of awk code (see below) that generates random numbers. gawk -F"," 'BEGIN { srand(); for (i = 1; i <= 30; i++) printf("%s AM329_%04d\n",$0,int(36 * rand())+1) }' OFS=, AM329_hole_names.csv The code works fine and generates alphanumeric numbers like AM329_0001,... (2 Replies)
Discussion started by: theflamingmoe
2 Replies

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

9. Shell Programming and Scripting

awk (or) UNIX random RGB colors generator?

Dear UNIX Friends, I was wondering if there is a random RGB color generator or any function in any unix platforms. Please share your ideas. Thanks (2 Replies)
Discussion started by: jacobs.smith
2 Replies
LOCALE_GET_ALL_VARIANTS(3)						 1						LOCALE_GET_ALL_VARIANTS(3)

Locale::getAllVariants - Gets the variants for the input locale

	Object oriented style

SYNOPSIS
publicstatic array Locale::getAllVariants (string $locale) DESCRIPTION
Procedural style array locale_get_all_variants (string $locale) Gets the variants for the input locale PARAMETERS
o $locale - The locale to extract the variants from RETURN VALUES
The array containing the list of all variants subtag for the locale or NULL if not present EXAMPLES
Example #1 locale_get_all_variants(3) example <?php $arr = locale_get_all_variants('sl_IT_NEDIS_ROJAZ_1901'); var_export( $arr ); ?> Example #2 OO example <?php $arr = Locale::getAllVariants('sl_IT_NEDIS_ROJAZ_1901'); var_export( $arr ); ?> The above example will output: array ( 0 => 'NEDIS', 1 => 'ROJAZ', 2 => '1901', ) SEE ALSO
locale_get_primary_language(3), locale_get_script(3), locale_get_region(3). PHP Documentation Group LOCALE_GET_ALL_VARIANTS(3)
All times are GMT -4. The time now is 05:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy