Sponsored Content
Full Discussion: Reading a file into an array
Top Forums UNIX for Dummies Questions & Answers Reading a file into an array Post 302336109 by zaxxon on Tuesday 21st of July 2009 08:54:25 AM
Old 07-21-2009
Example in ksh:
Code:
# cat infile
most people
just do not
use code tags
# set -A myarray `tr -s '\n' ' ' < infile`
# echo ${myarray[*]}
most people just do not use code tags

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: Reading out rows of a file into a dynamic array and check first literal

Hello, i have a file "Movie.ini" looking e.g. like follows * MOVIE A bla bla MOVIE B blubb blubb MOVIE C I'd like to read the file "Movie.ini" with cat and grep and check whether it includes the string MOVIE only with a '*' at the beginnig. By doing "cat Movie.ini| grep MOVIE... (14 Replies)
Discussion started by: ABE2202
14 Replies

2. Shell Programming and Scripting

Reading from array

Hi, I have an array like below... Table="table1" Table="table2" Table="table3" Table="table4" ..... Table="tablen" I want to retireve the values from the array and need to pass this to a db2 command to create a view like below. the number of values in the array will vary ... (1 Reply)
Discussion started by: ratheeshjulk
1 Replies

3. Programming

Reading Scientific notation from file and storing in array

Hi, I am trying to read a set of numbers that are in scientific notation into a file so I can do some math on them, but when I display the array contents the numbers aren't the same as the numbers in the file. Could someone explain why? Thanks. int main() { double fArray; ... (3 Replies)
Discussion started by: Filter500
3 Replies

4. Shell Programming and Scripting

Reading from a file and assigning to an array in perl

I wrote a simply perl that searched a file for a particualr value and if it found it, rite it and the next three lines to a file. Now I have been asked to check those next three lines for a different value and only write those lines if it finds the second value. I was thinking the best way to... (1 Reply)
Discussion started by: billprice13
1 Replies

5. Shell Programming and Scripting

reading data from a file to an array

I need some help with this code below, i doesnt know why it will run twice with my function, but my function only got if else, any other way that can read line and put into array? while read line; do read -A array <<<$line n=${#array} for ((i=1;i<$n;i++)); do print... (1 Reply)
Discussion started by: gavin_L
1 Replies

6. Shell Programming and Scripting

Help with reading column in array

I have some version problem to use this code in my server while read line; do read -A array <<<$line <---------- the server dont read <<< n=${#array} for ((i=1;i<$n;i++)); do print "${array}" done func=${array} data1=${array} data2=${array} ... (1 Reply)
Discussion started by: gavin_L
1 Replies

7. Shell Programming and Scripting

Reading columns from a text file and to make an array for each column

Hi, I am not so familiar with bash scripting and would appreciate your help here. I have a text file 'input.txt' like this: 2 3 4 5 6 7 8 9 10 I want to store each column in an array like this a ={2 5 8}, b={3 6 9}, c={4 7 10} so that i can access any element, e.g b=6 for the later use. (1 Reply)
Discussion started by: Asif Siddique
1 Replies

8. Shell Programming and Scripting

Reading a file into array

Hi, I need to read a file into array and print them in a loop:- 1st file :-cat a.txt RC1 RC2 RC3 RC4 My Program:- #!/bin/ksh index=0 while do read cnt<a.txt print "cnt value is ${cnt} index=`expr $index + 1` done Code tags for code, please. (5 Replies)
Discussion started by: satishmallidi
5 Replies

9. Shell Programming and Scripting

Reading a file into an array

Hi I have a file with contents as below : server | ABC Issue : File System Missing XYZ Issue : Wrong Syntax PQR Issue : Old File to be removed Now I am looking for an o/p similar to server <tab> ABC Issue : File System Missing <tab> XYZ Issue : Wrong Syntax <tab>... (4 Replies)
Discussion started by: deo_kaustubh
4 Replies

10. Shell Programming and Scripting

Help reading the array and sum of the array elements

Hi All, need help with reading the array and sum of the array elements. given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large. Input Format The first line of the input consists of an... (1 Reply)
Discussion started by: nishantrefound
1 Replies
PMDAEVENTARRAY(3)					     Library Functions Manual						 PMDAEVENTARRAY(3)

NAME
pmdaEventNewArray, pmdaEventResetArray, pmdaEventReleaseArray, pmdaEventAddRecord, pmdaEventAddMissedRecord, pmdaEventAddParam, pmdaEvent- GetAddr - utilities for PMDAs to build packed arrays of event records C SYNOPSIS
#include <pcp/pmapi.h> #include <pcp/impl.h> #include <pcp/pmda.h> int pmdaEventNewArray(void); int pmdaEventResetArray(int idx); int pmdaEventReleaseArray(int idx); int pmdaEventAddRecord(int idx, struct timeval *tp, int flags); int pmdaEventAddMissedRecord(int idx, struct timeval *tp, int nmissed); int pmdaEventAddParam(int idx, pmID pmid, int type, pmAtomValue *avp); pmEventArray *pmdaEventGetAddr(int idx); cc ... -lpcp DESCRIPTION
A Performance Metrics Domain Agent (PMDA) that wishes to export event records (or trace records) is encouraged to use a metric of type PM_TYPE_EVENT to encode a group of event records into a single packed array. The packed array of event records format is defined in <pcp/pmapi.h> and consists of a pmEventArray structure, containing a variable number of pmEventRecord structures, each of which contains a variable number of pmEventParameter structures, which in turn may contain a variable length value for each parameter of each event record. The routines described here are designed to assist the PMDA developer in building a packed array of event records, and managing all of the memory allocations required to hold each instance of an array of event records in a contiguous buffer. Normal use would be as part of PM- DA's pmdaFetchCallBack method. pmdaEventNewArray is used to create a new event array. The return value is a small integer that is used as the idx parameter to the other routines to identify a specific event array. If needed, a PMDA can create and use multiple event arrays. To start a new cycle and refill an event array from the beginning, call pmdaEventResetArray. If the PMDA has finished with an event array, pmdaEventReleaseArray may be used to release the underlying storage and ``close'' the event array so that subsequent attempts to use idx will return PM_ERR_NOCONTEXT. To start a new event record, use pmdaEventAddRecord. The timestamp for the event record is given via tp and the flags parameter may be used to set the control field that determines the type of the event record - flags may be the bit-wise ``or'' of one or more of the PM_EVENT_FLAG_* values defined in <pcp/pmapi.h> (but note that PM_EVENT_FLAG_MISSED should not be used in this context). If event records have been missed, either because the PMDA cannot keep up or because the PMAPI client cannot keep up, then pmdaEventAd- dMissedRecord may be used. idx and tp have the same meaning as for pmdaEventAddRecord and nmissed is the number of event records that have been missed at this point in the time-series of event records. pmdaEventAddMissedRecord may be called multiple times for a single batch of event records if there are more than one ``missed event record'' episode. Once an event record has been started by calling pmdaEventAddRecord, one or more event parameters may be added using pmdaEventAddParam. The pmid and type parameters decribe the PMID of the parameter and the data type (one of the PM_TYPE_* values from <pcp/pmapi.h>) of the value that is passed via avp. type should one where the size of the value is implied by the type or by the length of a string value (for PM_TYPE_STRING) or encoded within avp->vbp (for PM_TYPE_AGGREGATE). Once the packed array has been constructed, pmdaEventGetAddr should be used to initialize the ea_type and ea_len fields at the start of the pmEventArray and return the base address of the event array that is assigned to the vp field of the pmAtomValue structure that the pmdaFetchCallBack method should return. EXAMPLE
The following skeletal code shows how these routines might be used. int sts; int myarray; int first = 1; pmEventArray eap; if (first) { first = 0; if ((myarray = pmdaEventNewArray()) < 0) { // report error and fail } } pmdaEventResetArray(myarray); // loop over all event records to be exported ... { struct timeval stamp; int flags; // establish timestamp and set flags to 0 or some combination // of PM_EVENT_FLAG_POINT, PM_EVENT_FLAG_START, PM_EVENT_FLAG_ID, // etc if ((sts = pmdaEventAddRecord(myarray, &stamp, flags)) < 0) { // report error and fail } // loop over all parameters for this event record ... { pmID pmid; int type; pmAtomValue atom; // construct pmid, type and atom for the parameter and // its value if ((sts = pmdaEventAddParam(myarray, pmid, type, &atom)) < 0) { // report error and fail } } // if some event records were missed (could be at the start // of the exported set, or at the end, or in the middle, or // a combination of multiple missed record episodes) ... { int nmiss; struct timeval stamp; if ((sts = pmdaEventAddMissedRecord(myarray, &stamp, nmiss)) < 0) { // report error and fail } } } // finish up eap = pmdaEventGetAddr(myarray); SEE ALSO
pmdaEventNewQueue(3), pmdaEventNewClient(3), PMDA(3) and pmEventFlagsStr(3). Performance Co-Pilot PCP PMDAEVENTARRAY(3)
All times are GMT -4. The time now is 12:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy