to assign cut values to an array


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers to assign cut values to an array
# 1  
Old 10-29-2007
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[0]=asd
var[1]=rgbh.. and so on
how do i do this. i need to reuse the values stored in the arrays.Is it possible.. ?
how do i do it using awk command?

Last edited by Syms; 10-29-2007 at 07:36 AM..
# 2  
Old 10-29-2007
Code:
echo "asd,rgbh,(,rty,got,),sroe,9034," | awk -F"," '{ split($0, arr, ","); }END{ for ( i in arr ) { print arr[i] } }'

# 3  
Old 10-29-2007
in bash
Code:
# IFS=,
# v="asd,rgbh,(,rty,got,),sroe,9034,"
# set -- $v
# echo $1
asd
# echo $3
(
# echo $#
8
# echo $@
asd rgbh ( rty got ) sroe 9034

# 4  
Old 10-29-2007
hi matrix.
i need to reuse the variables ..meaning... if i say echo "$arr[1]" i m getting the output as [1].. i want the value stored in arr[1]. how do i get that?
# 5  
Old 10-29-2007
hi ghostdog,
i need the script in ksh .. can plz help me with that.. ?
# 6  
Old 10-29-2007
Quote:
Originally Posted by Syms
hi matrix.
i need to reuse the variables ..meaning... if i say echo "$arr[1]" i m getting the output as [1].. i want the value stored in arr[1]. how do i get that?
array variable within the awk contains the values and it could be readily used.
arr[1]
arr[2]

Not sure what you are looking for.
# 7  
Old 10-29-2007
hi madan .. i need to reuse the array variable outside the awk command..
echo ",asd,rgbh,(,rty,got,),sroe,9034," | awk -F"," '{ split($0, arr, ","); }END{ for ( i in arr ) { print arr[i] } }'
echo " $arr[1]"..
here the echo command does not give me the values stored in arr[1]..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How To Read a File and Assign the line values to an Array?

i have this basic code that i wrote to read a file and place it's values to an array. the source/input file will have multiple strings on it that is separated by a whitespace. sample_list.txt file contents: ACCT1 TABLE1 ACCT2 TABLE2 ACCT3 TABLE3 script file: sample_list.sh ... (3 Replies)
Discussion started by: wtolentino
3 Replies

2. Shell Programming and Scripting

How to assign value to variable using cut?

Hey guys. Below is the command I am using to assign "yellow" to the variable yellow. I can seem to echo it out using xargs but when I assign it to yellow and then try to echo it out it prints a blank line. Below is the command. Your help is highly appreciated! cut -c 2- color.txt |... (11 Replies)
Discussion started by: eldan88
11 Replies

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

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

5. Shell Programming and Scripting

Read variables names from array and assign the values

Hi, I have requirement to assign values to variables which are created dynamically. Below is the code which i am using to achieve above requirement. #!/bin/ksh oIFS="$IFS"; IFS=',' STR_FAIL_PARENT_IF_FAILS="WF_F_P_IF_FAILS1,WF_F_P_IF_FAILS2,WF_F_P_IF_FAILS3" set -A... (1 Reply)
Discussion started by: tmalik79
1 Replies

6. Shell Programming and Scripting

Cut text and assign them into array

file.txt : is delimiter: abc:def:ghi jkl:mno: pqr 123:456:789 if I do the cut command, and cut the first column, and echo it out I will get the output: abc jkl 123 How can I assign the column of text that I've cut into Array? e.g If I were to echo array array it will output as:... (9 Replies)
Discussion started by: andylbh
9 Replies

7. Shell Programming and Scripting

Select multiple values from an Oracle database and assign it to two dimensional array

hi I have two tables in oracle DB and am using a joining query which will result in the output as follows. i need to assign it to a two dimensional array and use it for my further calculations. the way i tried is as follows. #!/bin/ksh export... (1 Reply)
Discussion started by: aemunathan
1 Replies

8. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

9. UNIX for Dummies Questions & Answers

Cut Command value assign to variable

Hi, I am new to UNIX Scripting. I have been trying to use the CUT command to retrieve part of the header from a file and assign it to a variable. I have tried searching a lot, but I am still unsuccessful. Sample Header: HJAN BALANCE 20090616 I need to retrieve the date here, which always... (10 Replies)
Discussion started by: ragz_82
10 Replies

10. Shell Programming and Scripting

Assign variables with cut

I need to read a file (a list) and assign the value to a variable (for each line), I'm looping until the end of the file. My problem is, I want to assign 2 separate variables from the list. The process I'm using is: awk '{print $3}' file1 > file2 awk '{print $4}' file1 > file3 cat file2... (2 Replies)
Discussion started by: douknownam
2 Replies
Login or Register to Ask a Question