Sponsored Content
Top Forums Shell Programming and Scripting How to read values and store in array? Post 302674133 by clx on Thursday 19th of July 2012 04:38:52 AM
Old 07-19-2012
Quote:
Originally Posted by Prachi Gupta
Code:
			if[ grep -w 'Task started' && $var1]
			then
				cut -d"|" -f1 Sri1.log >> time.txt
			fi

But gives the error
Code:
syntax error near unexpected token 'then'

Please guide me to resolve this
There must be a space on both side of "[" and "]"
Inner commands should be first executed, $(..) or `...`
Also, when using && constructs, you should probably use ..
Code:
if [ "$(grep -w 'Task started')" ] && [ $var1 ]
			then
				cut -d"|" -f1 Sri1.log >> time.txt
			fi

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how do I store the values in array using shell

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)
Discussion started by: krishna
2 Replies

2. UNIX for Dummies Questions & Answers

How to store the values in a file into an array

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)
Discussion started by: risshanth
3 Replies

3. UNIX for Dummies Questions & Answers

trouble using read to store values in variables from command output

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)
Discussion started by: ProGrammar
2 Replies

4. Shell Programming and Scripting

Read textfile and enter the values in array

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)
Discussion started by: luna_soleil
3 Replies

5. Shell Programming and Scripting

Store values in an Array

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)
Discussion started by: crcbad
8 Replies

6. Shell Programming and Scripting

Not able to read unique values in array

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)
Discussion started by: faiz1985
1 Replies

7. Shell Programming and Scripting

Store values from a file into an array variable in Shell

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)
Discussion started by: ezhil01
2 Replies

8. Shell Programming and Scripting

Store the output values in array

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)
Discussion started by: KarthikPS
2 Replies

9. UNIX for Dummies Questions & Answers

How to store/read multiple values from a varible

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)
Discussion started by: jeanzibbin
2 Replies

10. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

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
Arch::SharedIndex(3pm)					User Contributed Perl Documentation				    Arch::SharedIndex(3pm)

NAME
Arch::SharedIndex - a synchronized data structure (map) for IPC SYNOPSIS
use Arch::SharedIndex; my $map = Arch::SharedIndex->new(file => "/tmp/logintimes.idx"); my $time = time; $map->store(migo => $time - 75, bob => $time - 5, enno => $time); printf "All users: %s, %s, %s ", $map->keys; printf "New users: %s ", $map->grep(sub { $_[1] == $time }); printf "Login time of migo: %s ", $map->fetch('migo'); $map->update(sub { $_[1] + 10 }, sub { $_[1] == $time }); $map->store(migo => $time); $map->delete('bob'); printf "Logged users with times: (%s) ", join(", ", $map->hash); DESCRIPTION
Arch::SharedIndex provides a key-value map that can be shared and accessed safely by multiple processes. METHODS
The following methods are available: new, encode_value, decode_value, store_value, fetch_value, delete_value, store, fetch, delete, fetch_store, keys, values, hash, list, grep, filter, update, query_index_list. new options Create a new index object. option is a hash of parameters. file The path of the index file, used to store data. Must not be omitted. can_create Whether the index file is automatically created. Defaults to 1. max_size Maximum number of entries in the index. Defaults to 0 (no limit). expiration Timeout in seconds after which unused entries are removed. Defaults to 0 (don't expire entries) time_renewal Whether fetching values resets the entry expiration timeout. Defaults to 1 if max_size is set, 0 otherwise. perl_data Whether non-scalar perl data can be stored. If true, values are encoded using Data::Dumper. perl_data_indent Indent value for Data::Dumper when perl_data is set. Defaults to 0. perl_data_pair Pair value for Data::Dumper when perl_data is set. Defaults to "=>". encode_value ref Encode the value referenced by ref in a string representation. The encoding is done in place. decode_value ref Decode a value encoded with encode_value from its string representation. The decoding is done in place. store_value key token value Store a value for the given key and token. Create a new token if none is given. Returns the (new) token. Sub-classes should implement this method. fetch_value key token Fetch the value stored for the given key and token. Sub-classes should implement this method. delete_value key token Delete a value stored for the given key and value. Sub-classes should implement this method. store kvp Store a set of key-value pairs. kvp may either be a reference to a hash or array, or list of keys and values. fetch keys Fetch values stored for a list of keys. keys may either be an array reference, or a list of keys. delete keys Delete values stored for a list of keys. keys may either be an array reference, or a list of keys. fetch_store mapfunc keys This is an optimized (fetch or store) in a single step. Fetch values stored for keys, just like fetch, but store values for the missing keys in the process. keys may be an array reference or a list of keys. mapfunc will be called once for every key in keys that has no associated value, with the key as its only argument. Its return value will be stored for that key. keys Returns a list of all valid keys. In scalar context, returns an array reference. Keys are returned in no particular order, but values will return values in matching order if the index has not been changed between calls. values Returns a list of all stored values. In scalar context, returns an array reference. Values are returned in no particular order, but keys will return values in matching order if the index has not been changed between calls. hash Returns the stored keys and values as a perl hash. In scalar context, returns hash reference. list Returns the stored keys and values as a list of pairs (array references with two elements each). In scalar context, returns an array reference. grep predicate Returns a list of keys for which predicate returns a true value. predicate is called once for every key, with the key and the stored value as its first and second argument. filter predicate Deletes every entry for which predicate returns a true value. predicate is called once for every key, with the key and the stored value asi its first and second argument. update mapfunc predicate Updates the value for every key for which predicate returns a true value with the return value from mapfunc. Both predicate and mapfunc are called with the key and the stored values as their first and second argument. update_index_list code Synchronize access and call code with a reference to a list of pairs, each containing the key and token, for every stored value. Used internally by store, fetch, delete, fetch_store, keys, values, hash, list, grep, filter and update. BUGS
Awaiting for your reports. AUTHORS
Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel). Enno Cramer (uebergeek@web.de--2003/arch-perl--devel). SEE ALSO
For more information, see Arch::SharedCache. perl v5.10.1 2005-09-17 Arch::SharedIndex(3pm)
All times are GMT -4. The time now is 03:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy