Results of command execution into array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Results of command execution into array
# 1  
Old 08-18-2008
Results of command execution into array

Hi

Can anybody tell me how can I dump the results of execution of a command into array form? For example, I want to execute:

Quote:
fdisk -l | grep 83 | grep Linux
and put each part of the result in an array element:

Quote:
root /home/alireza Revolution 1# fdisk -l | grep 83 | grep Linux
/dev/sda1 1 15000 120487468+ 83 Linux
/dev/sda2 15001 20837 46885702+ 83 Linux
/dev/sda5 20838 21969 9092789+ 83 Linux
/dev/sda6 21970 23101 9092789+ 83 Linux
/dev/sda7 23102 27000 31318717 83 Linux
/dev/sdb1 1 2361 18964701 83 Linux
/dev/sdb3 2362 4722 18964732+ 83 Linux
/dev/sdb5 4723 7033 18563076 83 Linux
/dev/sdb6 7034 9344 18563076 83 Linux
/dev/sdb7 9345 11655 18563076 83 Linux
/dev/sdb8 11656 13966 18563076 83 Linux
/dev/sdb9 13967 16277 18563076 83 Linux
/dev/sdb10 16278 18588 18563076 83 Linux
/dev/sdb11 18589 20899 18563076 83 Linux
/dev/sdb12 20900 23210 18563076 83 Linux
/dev/sdb13 23211 25521 18563076 83 Linux
/dev/sdb14 25522 27832 18563076 83 Linux
/dev/sdb15 27833 29000 9381928+ 83 Linux
/dev/sdc1 1 8941 71818551 83 Linux
Thanks
# 2  
Old 08-19-2008
If your system supports process substitution:

Code:
IFS='\
' read -d'^Y' -a array < <(fdisk -l | grep 83 | grep Linux)

'^Y' is just a randomly chosen character that should not occur in the input data (entered using Ctrl-V Ctrl-Y).

Last edited by Annihilannic; 08-19-2008 at 01:00 AM.. Reason: process substitution, not named pipes
# 3  
Old 08-19-2008
If it doesn't support process substitution. Try this:

Code:
fdisk -l | grep 83 | grep Linux > /tmp/tempfile
IFS='\
' read -d'^Y' -a array < /tmp/tempfile


Last edited by Annihilannic; 08-19-2008 at 01:00 AM.. Reason: process substitution, not named pipes
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Results Of A Variable Into An Array Using C Language

Can C add its results into an array like bash? For example using bash: cat /etc/passwd **truncated for space ** gdm:x:109:118:Gnome Display Manager:/var/lib/gdm:/bin/false mysql:x:110:122:MySQL Server,,,:/nonexistent:/bin/false statd:x:111:65534::/var/lib/nfs:/bin/false... (5 Replies)
Discussion started by: metallica1973
5 Replies

2. Shell Programming and Scripting

Append awk results into file or array

for a in {1..100} do awk '{ sum+=$a} END {print sum}' a=$a file1 > file2 done I know I will get only one number if following the code above, how can I get 100 sum numbers in file2? (2 Replies)
Discussion started by: wanliushao
2 Replies

3. Shell Programming and Scripting

Storing the SQL results in array variables

Requirement 1) I need to execute 15 SQL queries in oracle through linux script. All these query results needs to be stored in array variables. Requirement 2) And these 15 queries needs to be executed in parallel. Requirement 3) Once all the queries executed then the shell script should... (3 Replies)
Discussion started by: Niranjancse
3 Replies

4. Shell Programming and Scripting

Multiple command execution inside awk command during xml parsing

below is the output xml string from some other command and i will be parsing it using awk cat /tmp/alerts.xml <Alert id="10102" name="APP-DS-ds_ha-140018-componentFailure-S" alertDefinitionId="13982" resourceId="11427" ctime="1359453507621" fixed="false" reason="If Event/Log Level(ANY) and... (2 Replies)
Discussion started by: vivek d r
2 Replies

5. Shell Programming and Scripting

Echoing command results

Sorry folks, Second time today. I am working on a script that accepts data via pipe and processes it. I expect it to work as: # command | ProcScript.sh Within ProcScript.sh, I want to be able to give the target of the prev run command I am using history 2 | grep -v history | awk... (18 Replies)
Discussion started by: Marc G
18 Replies

6. Shell Programming and Scripting

Want to terminate command execution when string found in the command output

Hi Experts, I am very much new to linux scripting, I am currently working on reducing my manual work and hence writing a script to automate few task. I am running below command to snmpwalk the router.. snmpwalk -v 3 -u WANDL_SU -a MD5 -A vfipmpls -x DES -X VfIpMpLs -l authPriv... (19 Replies)
Discussion started by: Hanumant.madane
19 Replies

7. Shell Programming and Scripting

Adding results of a find to an array

I'm trying to add the paths of all the xml files in certain directories to an array. I want to use the array later in my code. Anyway, for some reason this isn't working. Any help would be appreciated. Path_Counter=0 for result in "find * -name '*.xml'"; do XmlPath="$result" echo... (2 Replies)
Discussion started by: Fly_Moe
2 Replies

8. Shell Programming and Scripting

Results of "find" to an array

I am looking to search a directory for a folder or file and when it finds any hits I want it to store those hits in an array so I can work with those hits later on. I have been trying to do something like this but it isn't putting results into an array like I would like, is it syntax or is this... (8 Replies)
Discussion started by: tret
8 Replies

9. Shell Programming and Scripting

Compare Array results

Hi, In a kshell , i need to compare the results of two array . each Non-match value should copy to a new array. For example: ========== Array one contain the following values: A B C Array two contain the following values: C F A E After comparing this arrays , a new array should... (4 Replies)
Discussion started by: yoavbe
4 Replies

10. Shell Programming and Scripting

getting results after using ps command

Hi, I want to use the following ps coomand: ps -ef | grep test Result of this command is: Test 161220 1 0 Oct 04 - 1:11 /test/test Just mentioning the description of each value in the result: UID PID PPID C STIME TTY TIME CMD Test 161220... (11 Replies)
Discussion started by: yale_work
11 Replies
Login or Register to Ask a Question