You do it straightforward. An array is just another variable after all and variables in shell scripts can be created just by using them.
Alas you haven't said which shell you are using, so as your penance for omitting this vital information i just suppose you are using Korn shell (ksh) and if you don't you will have to translate my solution to your shell yourself. ;-))
Suppose the following input file. We want all the lines "data=<value>" and store the "<value>" in an indexed array (1-based):
Now the script, which will read it and put the content into an array, like stated above:
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)
Hi,
I do have a file and the contents are as follws:
10
20
30
40
50
Now I want to store those values into an array. How can be done this ?? (3 Replies)
I know there are caveats about using read in pipelines because read is treated by a subshell. I know this but I can't think of any way to accomplish this regardless, I'm still a rookie.
I hope somebody will be able to interpret what it is that I'm trying to accomplish and correct me.
... (2 Replies)
Hi,
I want to put values in .txt file into array. Example :
$vi repo.txt
abc
def
ghi
jkl
mno
pqr
i want the output to be like this:
$echo ${mydf}
abc
$echo ${mydf}
def
$echo ${mydf}
ghi (3 Replies)
Hi all.
Well, I have the next code:
I need to make an array with the values I have in the bucle, but just don't get it...
Question is, how can I store in an array that values, and how can I display them with echo? (8 Replies)
Hi Friends,
I am having some trouble reading into an array. Basically, I am trying to grep for a pattern and extract it's value and store the same into an array. For eg., if my input is:
<L:RECORD>name=faisel farooq,age=21,
company=TCS,project=BT</L:RECORD>
<L:RECORD>name=abc... (1 Reply)
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)
Hi,
How to store the values in array from output result,
EG:
I have the result like this,
ps, google, 1.txt, 1
sam, google, 2.txt, 2
These are the four values followed by comma in two sets. I need to store these values set by set. One set contains four values followed by comma.
... (2 Replies)
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)
Here's my code:
awk -F '' 'NR==FNR {
if (/time/ && $5>10)
A=$2" "$3":"$4":"($5-01)
else if (/time/ && $5<01)
A=$2" "$3":"$4-01":"(59-$5)
else if (/time/ && $5<=10)
A=$2" "$3":"$4":0"($5-01)
else if (/close/) {
B=0
n1=n2;
... (2 Replies)
Discussion started by: klane
2 Replies
LEARN ABOUT OSF1
fetch
dbm(3) Library Functions Manual dbm(3)NAME
dbminit, fetch, store, delete, firstkey, nextkey, forder - Database subroutines
LIBRARY
DBM Library (libdbm.a)
SYNOPSIS
#include <dbm.h>
typedef struct {
char *dptr;
int dsize; } datum;
int dbminit(
char *file );
datum fetch(
datum key );
int store(
datum key,
datum content );
int delete(
datum key );
datum firstkey( void );
datum nextkey(
datum key );
long forder(
datum key );
PARAMETERS
Specifies the database file. Specifies the key. Specifies a value associated with the key parameter.
DESCRIPTION
The dbminit(), fetch(), store(), delete(), firstkey(), nextkey(), and forder() functions maintain key/content pairs in a database. They
are obtained with the -ldbm loader option. The dbm library is provided only for backwards compatibility, having been obsoleted by the ndbm
functions in libc. See the manual page for ndbm for more information.
The dbminit(), fetch(), store(), delete(), firstkey(), nextkey(), and forder() functions handle very large databases (up to a billion
blocks) and access a keyed item in one or two file system accesses. Arbitrary binary data, as well as normal ASCII strings, are allowed.
The database is stored in two files. One file is a directory containing a bit map and has .dir as its suffix. The second file contains
all data and has .pag as its suffix.
Before a database can be accessed, it must be opened by the dbminit() function. At the time that dbminit() is called, the file.dir and
file.pag files must exist. (An empty database is created by creating zero-length .dir and .pag files.)
Once open, the data stored under a key is accessed by the fetch() function and data is placed under a key by the store() function. A key
(and its associated contents) is deleted by the delete() function. A linear pass through all keys in a database may be made by use of the
firstkey() and nextkey() functions. The firstkey() function returns the first key in the database. With any key, the nextkey() function
returns the next key in the database. The following code traverses the database: for (key = firstkey(); key.dptr != NULL; key = nex-
tkey(key))
RETURN VALUES
Upon successful completion, the functions that return an int return 0 (zero). Otherwise, a negative number is returned. The functions
that return a datum indicate errors with a null (0) dptr .
RELATED INFORMATION
Functions: ndbm(3) delim off
dbm(3)