Sponsored Content
Top Forums Shell Programming and Scripting Storing command output in an array Post 302804889 by sanzee007 on Thursday 9th of May 2013 09:46:40 AM
Old 05-09-2013
Storing command output in an array

Hi,
I want keep/save one command's output in an array and later want to iterate over the array one by one for some processing. instead of doing like below-
Code:
for str in `cat /etc/passwd | awk -F: '$3 >100 {print $1}' | uniq`

want to store-
Code:
my_array[] = `cat /etc/passwd | awk -F: '$3 >100 {print $1}' | uniq`

and then want to do-
Code:
for str in my_array[]
do
...
done

shell is korn shell, sorry for syntax mistakes.

thanks in advance.Smilie

Last edited by Scott; 05-09-2013 at 11:02 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Storing pointer array in C

All .. I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced code: int cnt1; char *t_array; char *f_array; for(cnt1=0; cnt1<1000; cnt1++) { t_array =... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

2. Shell Programming and Scripting

storing variables in array.Please help

Hi All, I need some help with arrays. I need to take input from the user for hostname, username and password until he enters .(dot) or any other character and store the values in the variable array. I would further connect to the hostname using username and passwd and copy files from server to... (7 Replies)
Discussion started by: nua7
7 Replies

3. Shell Programming and Scripting

Storing output of "time" command to a variable

Hi all, I am new to Linux/shell scripting having moderate knowledge. In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For this i tried using "time" command to retrieve the total execution time in milli seconds. But, the problem is that, how to save... (9 Replies)
Discussion started by: happening_linux
9 Replies

4. Shell Programming and Scripting

How to store output of command to an array

Hello Guys, I am trying to store output of command to an array and then want to print, but it showing an error that "bad substitution". I am not getting why it's happening. Can anyone help me? #!/usr/bin/sh hr=0 min=0 i=1 last $1 | grep -w `date "+%b"` | grep -v '\(0:.*\)' | grep -vw sshd... (8 Replies)
Discussion started by: kasparov
8 Replies

5. Shell Programming and Scripting

Storing data in perl 2D array

Respected All, Kindly help me out. I have got file listings in a directory like this: -rw-r--r-- 1 root root 115149 2011-11-17 07:15 file1.stat.log -rw-r--r-- 1 root root 115149 2011-11-18 08:15 file2.stat.log -rw-r--r-- 1 root root 115149 2011-11-19 09:15 file3.stat.log -rw-r--r-- 1... (2 Replies)
Discussion started by: teknokid1
2 Replies

6. Programming

C; storing strings in an array

I am trying to get userinput from stdin and store the lines in an array. If i do this: using a char **list to store strings allocate memory to it #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { char *prog = argv; char **linelist; int... (5 Replies)
Discussion started by: tornow
5 Replies

7. Shell Programming and Scripting

Storing the Linux command output to an array in perl script

Hi I am trying to store the output of a command into an array in perl script. I am able to store but the problem is i am unable to print the array line with one line space. i mean i inserted the \n in loop ...but not getting the result. I have written like this #!/usr/bin/perl @a =... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

8. Shell Programming and Scripting

Storing command output in a variable and using cut/awk

Hi, My aim is to get the md5 hash of a file and store it in a variable. var1="md5sum file1" $var1 The above outputs fine but also contains the filename, so somthing like this 243ASsf25 file1 i just need to get the first part and put it into a variable. var1="md5sum file1"... (5 Replies)
Discussion started by: JustALol
5 Replies

9. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

10. Shell Programming and Scripting

Storing two dimensional array for postprocessing

Hi Community, Would love to get some quick help on below requirement. I am trying to process mpstat output from multiple blades of my server I would like to assign this the output to an array and then use it for post processing. How can I use a two dimensional array and assign these value ... (23 Replies)
Discussion started by: sshark
23 Replies
MONGOCOMMANDCURSOR(3)							 1						     MONGOCOMMANDCURSOR(3)

The MongoCommandCursor class

INTRODUCTION
A command cursor is similar to a MongoCursor except that you use it for iterating through the results of a database command instead of a normal query. Command cursors are useful for iterating over large result sets that might exceed the document size limit (currently 16MB) of a single MongoDB.command(3) response. While you can create command cursors using MongoCommandCursor.__construct(3) or the MongoCommandCursor.createFromDocument(3) factory method, you will generally want to use command-specific helpers such as MongoCollection.aggregateCursor(3). Note that the cursor does not "contain" the database command's results; it just manages iteration through them. Thus, if you print a cur- sor (f.e. with var_dump(3) or print_r(3)), you will see the cursor object but not the result documents. CURSOR STAGES
A MongoCommandCursor has two "life stages": pre- and post- command. When a cursor is created, it has not yet contacted the database, so it is in its pre-command state. When the client first attempts to get a result (by calling MongoCommandCursor.rewind(3), directly or indi- rectly), the cursor moves into the post-command state. The command cursor's batch size and socket timeout may be configured in both the pre- and post- command states. Example #1 Adding options to MongoCommandCursor <?php $cursor = new MongoCommandCursor(...); $cursor = $cursor->batchSize( 4 ); foreach ($cursor as $result) { var_dump($result); } ?> CLASS SYNOPSIS
MongoCommandCursor MongoCommandCursorMongoCursorInterfaceIterator Methods o public MongoCommandCursor MongoCommandCursor::batchSize (int $batchSize) o public MongoCommandCursor::__construct (MongoClient $connection, string $ns, array $command = array()) o publicstatic MongoCommandCursor MongoCommandCursor::createFromDocument (MongoClient $connection, string $hash, array $document) o public array MongoCommandCursor::current (void ) o public bool MongoCommandCursor::dead (void ) o public array MongoCommandCursor::getReadPreference (void ) o public array MongoCommandCursor::info (void ) o public int MongoCommandCursor::key (void ) o public void MongoCommandCursor::next (void ) o public array MongoCommandCursor::rewind (void ) o public MongoCommandCursor MongoCommandCursor::setReadPreference (string $read_preference, [array $tags]) o public MongoCommandCursor MongoCommandCursor::timeout (int $ms) o public bool MongoCommandCursor::valid (void ) SEE ALSO
o MongoDB::command o MongoCollection::aggregateCursor PHP Documentation Group MONGOCOMMANDCURSOR(3)
All times are GMT -4. The time now is 02:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy