07-05-2005
Reading in data sets into arrays from an input file.
Hye all,
I would like some help with reading in a file in which the data is seperated by commas. for instance:
input.dat:
1,2,34,/test
for the above case, the fn. will store the values into an array -> data[] as follows:
data[0] = 1
data[1] = 2
data[2] = 34
data[3] = /test
I am trying to write this fn. but dont know how to look for a comma so that the next data can be read in. Any help will be appreciated. Thanks in advance.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi All,
I am having trouble through, I am reading the input from tab delimited file containing several records,
e.g.
line1 field1 field2 field3 so on..
line2 field1 field2 field3 so on..
..
..
on the basis of certain fields for each record in input file, I have to retrieve... (1 Reply)
Discussion started by: Sonu4lov
1 Replies
2. Shell Programming and Scripting
Ok; here is the code
INCREMENT=0 #Final Count
MATCH=0 #Treated as a Boolean
declare -a LINEFOUR #Declared Array
for FILE in $DIR; do # DIR was declared earlier
test -f $FILE && (
TEMP=(sed -n '4p' $FILE) #How do I assign the fourth line of the file to TEMP? This doesn't... (1 Reply)
Discussion started by: Asylus
1 Replies
3. Shell Programming and Scripting
Hi,
I have tried to find some sort of previous similar thread on this but not quite close to what I want to achieve.
Basically I have two class of data in my file..e.g
1,1,1,1,1,2,yes
1,2,3,4,5,5,yes
2,3,4,5,5,5,no
1,2,3,4,4,2,no
1,1,3,4,5,2,no
I wanted to read the "yes" entry to an... (5 Replies)
Discussion started by: ahjiefreak
5 Replies
4. Shell Programming and Scripting
I am trying to read input for a C program (that expects input from the user) from a file using the shell command:
progname < filename
but it seems that the program considers the char '<'
as the first input, hence causing an "error" in my program.
I checked it with another program and it... (2 Replies)
Discussion started by: nadbar
2 Replies
5. Shell Programming and Scripting
Hi guys,
I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help.
I have 2 input files (example given below)
Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies
6. Shell Programming and Scripting
All,
I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then
Insert file1 column2 to file2 column4 then create a new file.
File1:
12345 Sam
12346 Bob
12347 Bill
File2:... (1 Reply)
Discussion started by: darkoth
1 Replies
7. Shell Programming and Scripting
hi all, i have a data file that contains 2 columns, names and numbers. i need to read names in to a an array call names and numbers in to an array call numbers. i also have # and blank lines in my dat file and i need to skip those when i read the dat file. how do i do this? btw, my column 1 and... (3 Replies)
Discussion started by: usustarr
3 Replies
8. Shell Programming and Scripting
Hello everybody!
I am quit new here and hope you can help me.
Using an awk script I am trying to extract data from several files. The structure of the input files is as follows:
TimeStep parameter1 parameter2 parameter3 parameter4
e.g.
1 X Y Z L
1 D H Z I
1 H Y E W
2 D H G F
2 R... (2 Replies)
Discussion started by: Daniel8472
2 Replies
9. Open Source
I have a process that requires me to read data from huge log files and find the most recent entry on a per-user basis. The number of users may fluctuate wildly month to month, so I can't code for it with names or a set number of variables to capture the data, and the files are large so I don't... (7 Replies)
Discussion started by: rbatte1
7 Replies
10. Shell Programming and Scripting
Hello,
I am running under ubuntu1 14.04 and I have a script which is sending given process names to vanish so that I'd see less output when I run most popular tools like top etc in terminal window. In usual method it works.
Whenever I restart the system, I have to enter the same data from... (2 Replies)
Discussion started by: baris35
2 Replies
LEARN ABOUT DEBIAN
font::ttf::segarr
Font::TTF::Segarr(3pm) User Contributed Perl Documentation Font::TTF::Segarr(3pm)
NAME
Font::TTF::Segarr - Segmented array
DESCRIPTION
Holds data either directly or indirectly as a series of arrays. This class looks after the set of arrays and masks the individual sub-
arrays, thus saving a class, we hope.
INSTANCE VARIABLES
All instance variables do not start with a space.
The segmented array is simply an array of segments
Each segment is a more complex affair:
START
In terms of the array, the address for the 0th element in this segment.
LEN Number of elements in this segment
VAL The array which contains the elements
METHODS
Font::TTF::Segarr->new($size)
Creates a new segmented array with a given data size
$s->fastadd_segment($start, $is_sparse, @dat)
Creates a new segment and adds it to the array assuming no overlap between the new segment and any others in the array. $is_sparse
indicates whether the passed in array contains "undef"s or not. If false no checking is done (which is faster, but riskier). If equal to 2
then 0 is considered undef as well.
Returns the number of segments inserted.
$s->add_segment($start, $overwrite, @dat)
Creates a new segment and adds it to the array allowing for possible overlaps between the new segment and the existing ones. In the case of
overlaps, elements from the new segment are deleted unless $overwrite is set in which case the elements already there are over-written.
This method also checks the data coming in to see if it is sparse (i.e. contains undef values). Gaps cause new segments to be created or
not to over-write existing values.
$s->tidy
Merges any immediately adjacent segments
$s->at($addr, [$len])
Looks up the data held at the given address by locating the appropriate segment etc. If $len > 1 then returns an array of values, spaces
being filled with undef.
$s->remove($addr, [$len])
Removes the item or items from addr returning them as an array or the first value in a scalar context. This is very like "at", including
padding with undef, but it deletes stuff as it goes.
$s->copy
Deep copies this array
$s->copy_seg($seg)
Creates a deep copy of a segment
BUGS
No known bugs.
AUTHOR
Martin Hosken Martin_Hosken@sil.org. See Font::TTF::Font for copyright and licensing.
perl v5.10.1 2009-01-21 Font::TTF::Segarr(3pm)