how to read delimited text into array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to read delimited text into array
# 1  
Old 03-19-2010
how to read delimited text into array

I am trying to parse a string using delimited char into array.
BNAME=B10,B20,B30
B10.Q=X
B20.Q=Y
B30.Q=Z

I need to parsethe BNAME into array, then i will loop through array to execute command using these variables. like:
for i in $array
do
qload array[i] array[i].Q # execute command: qload B10 X
done
# 2  
Old 03-19-2010
Quote:
Originally Posted by adars1
I am trying to parse a string using delimited char into array.
BNAME=B10,B20,B30
B10.Q=X
B20.Q=Y
B30.Q=Z

I need to parsethe BNAME into array, then i will loop through array to execute command using these variables. like:
for i in $array
do
qload array[i] array[i].Q # execute command: qload B10 X
done
Code:
IFS=, set -- $BNAME
for b
do
  qload "$b" "$b.Q"
done

# 3  
Old 03-19-2010
Hi, adars1:

Code:
B10.Q

A dot is not a valid character in a shell variable.

Perhaps something like this will work for you:
Code:
#!/bin/sh

BNAME='B10 B20 B30'
B10=X
B20=Y
B30=Z

set -- $BNAME
for name in "$@"; do
    eval echo qload \$name \$$name
done

Running it gives:
Code:
$ ./adars1.sh 
qload B10 X
qload B20 Y
qload B30 Z

When you're ready to try it for real, remove the "echo" following the eval command.

Regards,
Alister
# 4  
Old 03-21-2010
BR_NAME='DONEBR10 DONEBR20'
# queue name
DONEBR10=X
DONEBR20=Y

set -- $BR_NAME
for name in "$@";
do
eval echo \$name \$$name
echo "---ddddd--------------------------"
done

-- I got follwing output
DONEBR10 DONEBR20 X DONEBR20
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

2. Shell Programming and Scripting

Read delimited file

I have a delimited file (,) containing Name, Amount,Type,Address,zip,Tel and Extn. If any of this column information is missing (except TYPE and Extn), I need to print that a spefic column value is missing in my output. Example: row 2 is missing ZIP and the out put should contain NOZIP in... (1 Reply)
Discussion started by: meet_calramz
1 Replies

3. Shell Programming and Scripting

How to extract field delimited by comma and store into an array?

hi, i have a variable which contains some file names separated by comma. example FNAME="abc.txt,def.txt,ghi.txt" i want to extract each filename and store it into an array and also count the number of files in the array. file=abc.txt file=def.txt file=ghi.txt i thought of using the... (8 Replies)
Discussion started by: Little
8 Replies

4. Shell Programming and Scripting

awk read one delimited file, search another delimited file

Hello folks, I have another doozy. I have two files. The first file has four fields in it. These four fields map to different locations in my second file. What I want to do is read the master file (file 2 - 23 fields) and compare each line against each record in file 1. If I get a match in all four... (4 Replies)
Discussion started by: dagamier
4 Replies

5. Shell Programming and Scripting

Delimited File to 2D Array

Hello, I need help in fetching data from a delimited file , into a 2D array. Sample Input File: "|" as delimiter A|123|446pr; B|46|hello89 krp; C|78|ystp90 67; D|ga|456; Please be advised that ";" is the line separator (not "\n"). Could you please write an awk script to... (5 Replies)
Discussion started by: vinay4889
5 Replies

6. Shell Programming and Scripting

How to read nth word from delimited text file?

Hi i am new in scripting how i can get 2 elements from first line of delimited txt file in shell scripts. AA~101010~0~AB~8000~ABC0~ BB~101011~0~BC~8000~ABC~ CC~101012~0~CD~8000~ABC0~ DD~101013~0~AB~8000~ABC~ AA~101014~0~BC~8000~ABC0~ CC~101015~0~CD~8000~ABC~ can anyone plse help?... (3 Replies)
Discussion started by: sushine11
3 Replies

7. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

8. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 Replies

9. UNIX for Dummies Questions & Answers

Read a tab delimited

OK, let's set this up. I have a tab delimited file from excel. In my UNIX shell I have the following lines IFS=`printf "\t"` while read LINE_NO SKIP IGNORE_ERRORS OTHER do .... This works fine if there is something in every column like this. NOTE, those are tabs, not spaces. :) ... (2 Replies)
Discussion started by: podzach
2 Replies

10. UNIX for Dummies Questions & Answers

Loading a comma Delimited file into an Array

Hello, I have been stuck on this aspect of loading a comma delimited file into an array. I thought i had the syntax right, but my commands are not working the way I want them to. Basically my cut command is splitting the file up by spaces and commas. I want the cut command to ignore white spaces.... (2 Replies)
Discussion started by: grandtheftander
2 Replies
Login or Register to Ask a Question