Assign value to array separated by #

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assign value to array separated by #
# 1  
Old 07-15-2011
Assign value to array separated by #

Hi all ,
I have a string like para1#para2#para3
i want to assign para1 as first element para2 as second and so on
i tried
set  -A array  para1#para2#para3
echo ${array[0]}
para1 para2 para3

i want echo ${array[0]}
# 2  
Old 07-15-2011
echo 'para1#para2#para3' | awk 'NF+=0' FS=# OFS='\n'
# 3  
Old 07-15-2011
This works in my ksh
set  -A array  $str
echo ${array[0]}
echo ${array[1]}
echo ${arr[0]}
echo ${arr[1]}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assign comma separated values to a variable

Hi All, I wrote a database command that queries our application and outputs a whole bunch of values to a text file. I need to assign the output to two values. Here is a sample of the output: valueOne, checkOne valueTwo, checkTwo valueThree, checkThree I would like... (9 Replies)
Discussion started by: jeffs42885
9 Replies

2. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

3. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

4. Shell Programming and Scripting

Assigning Multiple Comma Separated IP's To A Bash Array

I am in the process of creating a BASH shell scripts for a project at work. So the scenario is as such: I have a file with each line entry separated by ':' ... (3 Replies)
Discussion started by: metallica1973
3 Replies

5. Programming

assign array with a local var???

Hi all, I am just wondering is this (below code) valid in programming int xx = 10110; int i; long yy = {1,2,3,4,5,6,7,8,xx}; I compiled this using gcc will all working option successfully without getting any warning or error. I didn't see this kind of code in my past... (7 Replies)
Discussion started by: zing_foru
7 Replies

6. Shell Programming and Scripting

assign value to array variable

Hi, I have a piece of code as follows: i=0 while read LINE do var = "$LINE" i=$((i+1)) echo "${var}" done < file I want to assign value to the array var. However, when i execute the script i get a error. Please can you help me know what i am missing. I ultimately want to... (2 Replies)
Discussion started by: sunrexstar
2 Replies

7. Shell Programming and Scripting

How to assign a variable to an array

I want to ask the user to enter an X amount of file names. I want to put those names into an array and then loop back through them to verify they are in the directory. 1st- How would I assign the value to an array and what is the correct syntax. 2nd- how would i reference that array after I... (3 Replies)
Discussion started by: tvb2727
3 Replies

8. Programming

Concatenating array of strings into one string separated by spaces

Hi, Well as the title says, I have an array of strings (delimited by null). The length of the array is variable and length of each string is variable as well. What I need is one huge string with the original strings in the array separated by spaces. For example is an array is such that array... (12 Replies)
Discussion started by: newhere
12 Replies

9. UNIX for Dummies Questions & Answers

to assign cut values to an array

i need to seperate values seperated by delimiters and assign it to an array.. can u plz help me on that. Variables = "asd,rgbh,(,rty,got,),sroe,9034," i need to assign the variables into arrays.. like.. var=asd var=rgbh.. and so on how do i do this. i need to reuse the values stored in... (6 Replies)
Discussion started by: Syms
6 Replies

10. Shell Programming and Scripting

Splitting comma separated values into an array

I'm attempting to create a KSH array out of a string like this: ",,,value1,value2,," I have created the array but I only get two elements, one for value1 and one for value2. I have ended up with something like this but I don't like it: set -A JUNK xx=0 for i in $(print ",,,value1,value2,,"... (3 Replies)
Discussion started by: tmarikle
3 Replies
Login or Register to Ask a Question