Sponsored Content
Top Forums Shell Programming and Scripting split varibles and store fields into shell varible array Post 302140259 by vgersh99 on Thursday 11th of October 2007 02:14:25 PM
Old 10-11-2007
or a bit simpler:
Code:
#!/bin/ksh

var='word1#word2|word3/word4|word5.word6|word7_word8|word9 word10|word11|word12'

IFS='|'; set -A arr $(echo "$var")
i=0
while (( i <= 6 ))
do
    echo "i=>[$i] (${arr[$i]})"
    ((i=i+1))
done

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how do I store the values in array using shell

Hi, Is is possible to get the value using shell script? x=1 y1 = 10 y2 = 15 y3 = 7 echo $y$x is giving y1 (variable name) but I need the value of y1 (i.e. 10 dynamically) Is there any solution? if so, please mail me at kkodava@maxis.com.my ... (2 Replies)
Discussion started by: krishna
2 Replies

2. Shell Programming and Scripting

How to store query multiple result in shell script variable(Array)

:) Suppose,I have one table A. Table A have one column. Table A have 10 rows. I want this 10 rows store into shell script variable. like #!/bin/ksh v_shell_var=Hi here in call oracle , through loop How can I store table A's 10 rows into v_shell_var (Shell Script Array). Regards, Div (4 Replies)
Discussion started by: div_Neev
4 Replies

3. Shell Programming and Scripting

How to store contents of a command in array of variables in shell script?

I want to store contents of command dir in array of variables For eg: dir contents are command d2 demovi~ file inven java new untitled folder d1 demovi er1 filename inven~ myfiles ubuntu desktop xmms ----------------------------------- I... (3 Replies)
Discussion started by: netresearch
3 Replies

4. Shell Programming and Scripting

how to split the row(array) in to fields and store in to oracle database in unix

Hi, the csv file with the delimeter #. A#B#C#D#E#F#G#H 1#2#3#4#5#6#7#8 Z#x#c#V 7#2#8#9 N. I want to read the file line by line and store in rowarray. then the rowarray content should be spilt or made to fields using the delimeter #. i am not sure can we store the fields in to... (3 Replies)
Discussion started by: barani75
3 Replies

5. Shell Programming and Scripting

how to spilit a row into fields and store the field content to the array

consider this is a line A#B#C#D#E#F#G#H note the delimeter is # i want to cut or spilt in to fields using the delimeter # and to store in an array. like this array=A array=B array=C array=D array=E and the array content should be displayed. echo "${array}" echo "${array}"... (5 Replies)
Discussion started by: barani75
5 Replies

6. Shell Programming and Scripting

Store values from a file into an array variable in Shell

Dear All, I have been trying to do a simple task of extracting 2 fields from the file (3 rows) and store it in an array variable. I tried with: #! /bin/bash ch=`cut -f10 tmp.txt` counter=0 for p in $pid do c=${ch} echo "$c ..$counter" counter=$((counter+1))... (2 Replies)
Discussion started by: ezhil01
2 Replies

7. Shell Programming and Scripting

split string into array in shell

Hi all, I want to split a string into array based on given delimiter, for example: String: "foo|bar|baz" with delimiter "|" into array: strArr to strArr with values foo, bar and baz. Thanks a lot. Roy987 (5 Replies)
Discussion started by: Roy987
5 Replies

8. UNIX for Dummies Questions & Answers

How to store/read multiple values from a varible

Hi, when I enter 'ps -ef| grep process_name'/'psu | grep process_name', i am getting multiple number of lines output( i mean multiple no of processes).how can i store it one by one and echo it in the same way(one by one). part of script is var1=$(remsh hostname -l username ps -ef|grep... (2 Replies)
Discussion started by: jeanzibbin
2 Replies

9. Shell Programming and Scripting

create an array which can store the strings from the user input in shell script

I want to create an array which can store the strings from the user input in shell script . example :- I want to store the 5 fruits name in a single array which the user provides . (1 Reply)
Discussion started by: Pkast
1 Replies

10. Shell Programming and Scripting

Shell script to loop and store in array

I'm trying to achieve the follwoinig with no luck. Find the directories that are greater than 50GB in size and pick the owner of the directory as I would like to send an alert notification. du -sh * | sort -rh 139G Dir_1 84G Dir_2 15G Dir_3 ls -l Dir_1 drwx------ 2... (3 Replies)
Discussion started by: 308002184
3 Replies
read(1) 						      General Commands Manual							   read(1)

NAME
read - read a line from standard input SYNOPSIS
var ... DESCRIPTION
reads a single line from standard input. The line is split into fields as when processed by the shell (refer to shells in the first field is assigned to the first variable var, the second field to the second variable var, and so forth. If there are more fields than there are specified var operands, the remaining fields and their intervening separators are assigned to the last var. If there are more vars than fields, the remaining vars are set to empty strings. The setting of variables specified by the var operands affect the current shell execution environment. Standard input to can be redirected from a text file. Since affects the current shell execution environment, it is usually provided as a normal shell special (built-in) command. Thus, if it is called in a subshell or separate utility execution environment similar to the following, it does not affect the shell variables in the caller's environment: Options recognizes the following options: Do not treat a backslash character in any special way. Consider each backslash to be part of the input line. Opperands recognizes the following operands: var The name of an existing or nonexisting shell variable. EXTERNAL INFLUENCES
Environment Variables determines the internal field separators used to delimit fields. RETURN VALUE
exits with one of the following values: 0 Successful completion. >0 End-of-file was detected or an error occurred. EXAMPLES
Print a file with the first field of each line moved to the end of the line. while read -r xx yy do printf "%s %s " "$yy" "$xx" done < input_file SEE ALSO
csh(1), ksh(1), sh(1), sh-posix(1). STANDARDS CONFORMANCE
read(1)
All times are GMT -4. The time now is 07:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy