Sponsored Content
Top Forums Shell Programming and Scripting how to spilit a row into fields and store the field content to the array Post 302397701 by kshji on Tuesday 23rd of February 2010 01:32:28 AM
Old 02-23-2010
Same answer as two days ago.

This work with all posix-sh compatible shells (ksh, posixsh, bash, ...).
Code:
oifs="$IFS"   # -save IFS value
IFS="#" 
flds=( $fileline )
IFS="oifs"    # - return original alue
nrofflds=${#flds[@]}

fld1="${flds[0]}"  
fld=0
while (( fld<nrofflds ))
do
       echo "{flds[$fld]}"  
       ((fld+=1))
done


Last edited by kshji; 02-23-2010 at 03:22 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split varibles and store fields into shell varible array

I need to split a long varible which is a whole line read from a file into fields and store them in an array, the fields are delimited by pipe and a field may contain white spaces. I tried the following concept test and it has problem with field 5 which contain a space, appearently so because... (3 Replies)
Discussion started by: gratus
3 Replies

2. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

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

4. Shell Programming and Scripting

Store all the passed arguments in an array and display the array

Hi I want to write a script which store all the parameters passed to the script into an array. Once it is stored I want scan through the array and and delete those files for last month present inside the directory. The files in directory is appneded with YYYY_MM_DD. I want to know how can I... (3 Replies)
Discussion started by: dgmm
3 Replies

5. Shell Programming and Scripting

Store content from array to Spread_sheet using perl

How to store the content from array to either "row-column" or "column-row" order? (0 Replies)
Discussion started by: kavi.mogu
0 Replies

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

7. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

8. Shell Programming and Scripting

Inserting a field without disturbing field separator on other fields

Hi All, I have the input as below: cat input 032016002 2.891 97.109 16.605 27.172 24.017 32.207 0.233 0.021 39.810 0.077 0.026 19.644 13.882 0.131 11.646 0.102 11.449 76.265 23.735 16.991 83.009 8.840 91.160 0.020 99.980 52.102 47.898 44.004 55.996 39.963 18.625 0.121 1.126 40.189... (15 Replies)
Discussion started by: am24
15 Replies

9. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

10. Shell Programming and Scripting

Analyzing last 2 fields of 1 row and 3rd field of next row

I have the following script that will average the last two fields of each row, but im not sure how to include the 3rd field of the following row. An example of the analysis that I need to perform from the input - (66.61+58.01+54.16)/3 awk '{sum=cnt=0; for (i=13;i<=NF;i++) { sum+=$i; cnt++... (1 Reply)
Discussion started by: ncwxpanther
1 Replies
SYBASE_FETCH_ASSOC(3)													     SYBASE_FETCH_ASSOC(3)

sybase_fetch_assoc - Fetch a result row as an associative array

SYNOPSIS
array sybase_fetch_assoc (resource $result) DESCRIPTION
sybase_fetch_assoc(3) is a version of sybase_fetch_row(3) that uses column names instead of integers for indices in the result array. Col- umns from different tables with the same names are returned as name, name1, name2, ..., nameN. An important thing to note is that using sybase_fetch_assoc(3) is NOT significantly slower than using sybase_fetch_row(3), while it pro- vides a significant added value. PARAMETERS
o $result - RETURN VALUES
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. NOTES
Note This function is only available when using the CT library interface to Sybase, and not with the DB library. SEE ALSO
sybase_fetch_row(3), sybase_fetch_array(3), sybase_fetch_object(3). PHP Documentation Group SYBASE_FETCH_ASSOC(3)
All times are GMT -4. The time now is 03:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy