Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Inaccurate scanning of Bash array elements Post 302989894 by RudiC on Thursday 19th of January 2017 12:54:44 PM
Old 01-19-2017
Running your final for loop with the variables (not arrays!) set to the values indicated, I get 0 0 0 9H KC 0 7C 9S, so the logics seem to be OK. The inconsistent behaviour might be caused by some creative use of variables, arrays, separators, and assignments.
The way you assign them, A and B will be arrays with one single element only. Scrutinizer already proposed an alternative use.
mapfile will (man bash) "Read lines from the standard input into the indexed array variable array", so again array PH has just one element as the input file has all cards in one line separated by spaces.
While the logics should work nevertheless, I can't assess the ramifications of using arrays vs. variables. Wouldn't it be worthwhile to try simple variables?


BTW, would your system allow for this construct:
Code:
Deck=$(shuf -e {2,3,4,5,6,7,8,9,T,J,Q,K,A}{H,S,D,C})


Last edited by RudiC; 01-19-2017 at 02:19 PM.. Reason: typo, small enhancement.
These 3 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Percent complete error while scanning RAID array during 5.0.6 load

Percent complete SCO 5.0.6 / No longer an issue (0 Replies)
Discussion started by: Henrys
0 Replies

2. UNIX for Dummies Questions & Answers

How can i read array elements dynamically in bash?

Hi friends how can we read array elements dynamically in bash shell? (1 Reply)
Discussion started by: haisubbu
1 Replies

3. Shell Programming and Scripting

How can I print array elements as different columns in bash?

Hi Guys, I have an array which has numbers including blanks as follows: 1 26 66 4.77 -0.58 88 99 11 12 333 I want to print a group of three elements as a different column in a file as follows:(including blanks where there is missing elements) for.e.g. array element #7... (4 Replies)
Discussion started by: npatwardhan
4 Replies

4. Shell Programming and Scripting

Removing elements from an array

Hi I have two arrays : @arcb= (450,625,720,645); @arca=(625,645); I need to remove the elements of @arca from elements of @arcb so that the content of @arcb will be (450,720). Can anyone sugget me how to perform this operation? The code I have used is this : my @arcb=... (3 Replies)
Discussion started by: rkrish
3 Replies

5. Shell Programming and Scripting

Grouping array elements - possible?

I have a script which takes backup of some configuration files on my server. It does that by using an array which contains the complete path to the files to backup. It copys the files to a pre defined dir. Each "program" has it's own folder, ex. apache.conf is being copied to /predefined... (7 Replies)
Discussion started by: dnn
7 Replies

6. Shell Programming and Scripting

Help reading the array and sum of the array elements

Hi All, need help with reading the array and sum of the array elements. given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large. Input Format The first line of the input consists of an... (1 Reply)
Discussion started by: nishantrefound
1 Replies

7. UNIX for Beginners Questions & Answers

Scanning array for partial elements in Bash Script

Example of problem: computerhand=(6H 2C JC QS 9D 3H 8H 4D) topcard=6D How do you search ${computerhand} for all elements containing either a "6" or a "D" then save the output to a file? This is a part of a Terminal game of Crazy 8's that I'm attempting to write in Bash. Any... (2 Replies)
Discussion started by: cogiz
2 Replies

8. UNIX for Beginners Questions & Answers

Random choice of elements in bash array

example of problem: #!/bin/bash P=(2 4 7) How would you randomly choose one of these 3 numbers in this array? either 2 or 4 or 7 is needed...but only one of them. Thanks in advance Cogiz Please use CODE tags as required by forum rules! (3 Replies)
Discussion started by: cogiz
3 Replies

9. Shell Programming and Scripting

Array to array scanning

trying a little bit of array scanning for open ports. my code looks like below: /bin/netstat -lntp|\ awk 'BEGIN { split("25 80 2020 6033 6010",q); } $1 == "tcp" { split($4,a,":"); p]++; } $1 == "tcp6" { split($4,a,":");p]++ } END { for ( i in q ) { if (! q in p ) {... (8 Replies)
Discussion started by: busyboy
8 Replies

10. Shell Programming and Scripting

Get unique elements from Array

I have an array code and output is below: echo $1 while read -r fline; do echo "%%%%%%$fline%%%%%" fmy_array+=("$fline") done <<< "$1" Output: CR30903 YU0007 SRIL CR30903 Yogesh SRIL %%%%%%CR30903 YU0007 SRIL%%%%% %%%%%%CR30903 Yogesh SRIL%%%%% ... (8 Replies)
Discussion started by: mohtashims
8 Replies
shuffle(1)							  Biosquid Manual							shuffle(1)

NAME
shuffle - randomize the sequences in a sequence file SYNOPSIS
shuffle [options] seqfile DESCRIPTION
shuffle reads a sequence file seqfile, randomizes each sequence, and prints the randomized sequences in FASTA format on standard output. The sequence names are unchanged; this allows you to track down the source of each randomized sequence if necessary. The default is to simply shuffle each input sequence, preserving monosymbol composition exactly. To shuffle each sequence while preserving both its monosymbol and disymbol composition exactly, use the -d option. The -0 and -1 options allow you to generate sequences with the same Markov properties as each input sequence. With -0, for each input sequence, 0th order Markov statistics are collected (e.g. symbol composition), and a new sequence is generated with the same composition. With -1, the generated sequence has the same 1st order Markov properties as the input sequence (e.g. the same disymbol frequencies). Note that the default and -0, or -d and -1, are similar; the shuffling algorithms preserve composition exactly, while the Markov algorithms only expect to generate a sequence of similar composition on average. Other shuffling algorithms are also available, as documented below in the options. OPTIONS
-0 Calculate 0th order Markov frequencies of each input sequence (e.g. residue composition); generate output sequence using the same 0th order Markov frequencies. -1 Calculate 1st order Markov frequencies for each input sequence (e.g. diresidue composition); generate output sequence using the same 1st order Markov frequencies. The first residue of the output sequence is always the same as the first residue of the input sequence. -d Shuffle the input sequence while preserving both monosymbol and disymbol composition exactly. Uses an algorithm published by S.F. Altschul and B.W. Erickson, Mol. Biol. Evol. 2:526-538, 1985. -h Print brief help; includes version number and summary of all options, including expert options. -l Look only at the length of each input sequence; generate an i.i.d. output protein sequence of that length, using monoresidue fre- quencies typical of proteins (taken from Swissprot 35). -n <n> Make <n> different randomizations of each input sequence in seqfile, rather than the default of one. -r Generate the output sequence by reversing the input sequence. (Therefore only one "randomization" per input sequence is possible, so it's not worth using -n if you use reversal.) -t <n> Truncate each input sequence to a fixed length of exactly <n> residues. If the input sequence is shorter than <n> it is discarded (therefore the output file may contain fewer sequences than the input file). If the input sequence is longer than <n> a contiguous subsequence is randomly chosen. -w <n> Regionally shuffle each input sequence in window sizes of <n>, preserving local residue composition in each window. Probably a bet- ter shuffling algorithm for biosequences with nonstationary residue composition (e.g. composition that is varying along the sequence, such as between different isochores in human genome sequence). -B (Babelfish). Autodetect and read a sequence file format other than the default (FASTA). Almost any common sequence file format is recognized (including Genbank, EMBL, SWISS-PROT, PIR, and GCG unaligned sequence formats, and Stockholm, GCG MSF, and Clustal align- ment formats). See the printed documentation for a complete list of supported formats. EXPERT OPTIONS
--informat <s> Specify that the sequence file is in format <s>, rather than the default FASTA format. Common examples include Genbank, EMBL, GCG, PIR, Stockholm, Clustal, MSF, or PHYLIP; see the printed documentation for a complete list of accepted format names. This option overrides the default expected format (FASTA) and the -B Babelfish autodetection option. --nodesc Do not output any sequence description in the output file, only the sequence names. --seed <s> Set the random number seed to <s>. If you want reproducible results, use the same seed each time. By default, shuffle uses a dif- ferent seed each time, so does not generate the same output in subsequent runs with the same input. SEE ALSO
afetch(1), alistat(1), compalign(1), compstruct(1), revcomp(1), seqsplit(1), seqstat(1), sfetch(1), sindex(1), sreformat(1), stranslate(1), weight(1). AUTHOR
Biosquid and its documentation are Copyright (C) 1992-2003 HHMI/Washington University School of Medicine Freely distributed under the GNU General Public License (GPL) See COPYING in the source code distribution for more details, or contact me. Sean Eddy HHMI/Department of Genetics Washington University School of Medicine 4444 Forest Park Blvd., Box 8510 St Louis, MO 63108 USA Phone: 1-314-362-7666 FAX : 1-314-362-2157 Email: eddy@genetics.wustl.edu Biosquid 1.9g January 2003 shuffle(1)
All times are GMT -4. The time now is 07:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy