Arrays are not a very good way to store this data you could simplify the code by using strings:
Code:
STR=81UV78UV183UV89800
for val in ${STR//UV/ }
do
echo $val
done
Anyway here is the method you want - note the final test as you have no terminating UV in your data:
Code:
#!/bin/bash
#String 1 (81UV78UV183UV89800) represents content of this array
#a[0]=8;a[1]=1;a[2]=U;a[3]=V;a[4]=7;a[5]=8;a[6]=U;
#a[7]=V;a[8]=1;a[9]=8;a[10]=3;a[11]=U;a[12]=V;
#a[13]=8;a[14]=9;a[15]=8;a[16]=0;a[17]=0;
a=( 8 1 U V 7 8 U V 1 8 3 U V 8 9 8 0 0 )
#String 2 (8U1UVV78UUV18UU3UV89800) represents content of this array
#a[0]=8;a[1]=U;a[2]=1;a[3]=U;a[4]=V;a[5]=V;a[6]=7;a[7]=8;
#a[8]=U;a[9]=U;a[10]=V;a[11]=1;a[12]=8;a[13]=U;a[14]=U;a[15]=3;a[16]=U;
#a[17]=V;a[18]=8;a[19]=9;a[20]=8;a[21]=0;a[22]=0;
#a=( 8 U 1 U V V 7 8 U U V 1 8 U U 3 U V 8 9 8 0 0 )
for (( i=0; i<${#a[@]}; i++))
do
if [ "${a[i]}${a[i+1]}" == "UV" ]; then
((i++))
if (( ${#buff} > 0 )); then
echo ${buff}
buff=""
fi
else
buff=${buff}${a[i]}
fi
done
if (( ${#buff} > 0 )); then
echo ${buff}
fi
Last edited by Chubler_XL; 12-17-2014 at 06:07 PM..
This User Gave Thanks to Chubler_XL For This Post:
Hi,
I have a file which has the below information
tm.orbit72
tm.orbit12
tm.orbit78
tm.orbitye
I want to print the last two letters in the above file. Please let me know how can i do that. (6 Replies)
hi Im trying to make the 'response' return the answer in the form of a dash (-) rather than the actuall letters of a given word typed in, this is what i have tried, but im not getting the dashes come through just a blank screen, any ideas guys?
function enterWord () {
echo "select to be... (2 Replies)
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)
hey
i m kinda new to this so i will appreciate any help
, i have this list of values:
pwwn = 0x50012482009cd7a7 nwwn=0x50012482009cd7a6 port_id = 0x280200
pwwn = 0x5001248201bcd7a7 nwwn=0x5001248201bcd7a6 port_id = 0x280300
pwwn = 0x50012482009c51ad nwwn=0x50012482009c51ac port_id =... (4 Replies)
Hey guys,
I'm new to shell scripting and I'm trying to write a script that takes user input and copies the specified columns from a data file to a new one. In order to account for the possibility of a variable number of columns to copy I wrote a loop that encodes the user's choices in an array... (16 Replies)
Hello,
In a shell script, I want to declare an array and subsequently print the elements with tab delimits.
My array has the following structure and arbitrary elements:
myArray=('fgh' 'ijk' 'xyz' 'abc');
Next, I would like to print it with a '\n' at the end.
Thanks for your input!
... (2 Replies)
Hello experts,
I wish to print the contents of odd-even numbered indices of an array.
The problem statement is as follows :
1. The first line contains an integer, (the number of test cases).
2. Each line of the subsequent lines containing a string.
Example:
2
Haider
Bash
... (4 Replies)
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)
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)
username=cogiz
#!/bin/bash
shuffle() #@ USAGE: shuffle
{ #@ TODO: add options for multiple or partial decks
Deck=$(
printf "%s\n" {2,3,4,5,6,7,8,9,T,J,Q,K,A}{H,S,D,C} |
awk '## Seed the random number generator
BEGIN { srand() }
## Put a random number in front... (4 Replies)
Discussion started by: cogiz
4 Replies
LEARN ABOUT REDHAT
des_read_password
ui_compat(3) OpenSSL ui_compat(3)NAME
des_read_password, des_read_2passwords, des_read_pw_string, des_read_pw - Compatibility user interface functions
SYNOPSIS
int des_read_password(DES_cblock *key,const char *prompt,int verify);
int des_read_2passwords(DES_cblock *key1,DES_cblock *key2,
const char *prompt,int verify);
int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
DESCRIPTION
The DES library contained a few routines to prompt for passwords. These aren't necessarely dependent on DES, and have therefore become
part of the UI compatibility library.
des_read_pw() writes the string specified by prompt to standard output turns echo off and reads an input string from the terminal. The
string is returned in buf, which must have spac for at least size bytes. If verify is set, the user is asked for the password twice and
unless the two copies match, an error is returned. The second password is stored in buff, which must therefore also be at least size
bytes. A return code of -1 indicates a system error, 1 failure due to use interaction, and 0 is success. All other functions described
here use des_read_pw() to do the work.
des_read_pw_string() is a variant of des_read_pw() that provides a buffer for you if verify is set.
des_read_password() calls des_read_pw() and converts the password to a DES key by calling DES_string_to_key(); des_read_2password() oper-
ates in the same way as des_read_password() except that it generates two keys by using the DES_string_to_2key() function.
NOTES
des_read_pw_string() is available in the MIT Kerberos library as well, and is also available under the name EVP_read_pw_string().
SEE ALSO ui(3), ui_create(3)AUTHOR
Richard Levitte (richard@levitte.org) for the OpenSSL project (http://www.openssl.org).
0.9.7a 2001-10-25 ui_compat(3)