System Output in to an Array or variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting System Output in to an Array or variable
# 1  
Old 11-15-2010
System Output in to an Array or variable

hey guys in only new to scripting as such, but i have a problem.
i want to take the output of a search i do in the command line to then be in a variable but only a certain part of the output.

this this what im doing:

-bash-2.05b$ ldapsearch -x '(dn:=dc)' dc|grep dc=
# base <dc=james,dc=morey,dc=home,dc=com> (default) with scope subtree

so "# base <dc=james,dc=morey,dc=home,dc=com> (default) with scope subtree" is what is put out from the command line
now i want to make the "dc=james,dc=morey,dc=home,dc=com" into a variable but just that!!! not the other stuff.

this is so when i create my ldif file it will put it in automatically for you
so instead i will call "dc=james,dc=morey,dc=home,dc=com" some thing like $DC
dc=james,dc=morey,dc=home,dc=com =$DC
my
$stuff= <<LDIF;

dn: uid=$UserName,ou=$OU,ou=$OU2,dc=james,dc=morey,dc=home,dc=com
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: $UserName
cn: $LastName $FirstName
givenName: $GivenName
mail: $UserName\@james.morey.com
sn: $FirstName
uidNumber: $UDI
gidNumber: $UDI
homeDirectory: /home/$UserName
loginShell: /bin/tcsh
userPassword: $b
dn: cn=$UserName,ou=$OU3,ou=$OU2,dc=james,dc=morey,dc=home,dc=comobjectClass: posixGroup
cn: $UserName
gidNumber: $UDI
description: Private group for the \"$UserName\" user"
LDIF
open
MYLDIF, ">", "init.ldif";

print
MYLDIF $stuff;

close
MYLDIF;


Last edited by jmorey; 11-15-2010 at 06:27 AM..
# 2  
Old 11-15-2010
Code:
 
ldapsearch -x '(dn:=dc)' dc|grep dc= | while read line
do
     DE=`echo $line | awk '{ n=split($1,arr,","); for(i=1;i<=n;i++){if(substr(arr[i],1,3)=="dc=") {if(j==1) str=str "," arr[i]; else str=arr[i]; j=1;}} printf("%s",str); }'`
     echo $DE;
done

It is assumed that "dc=value" pairs are comma separated.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

2. Shell Programming and Scripting

How to capture system() function output in variable

How to capture system() function output in awk variable and the print that awk variable..... (8 Replies)
Discussion started by: bharat1211
8 Replies

3. AIX

Oracle output to an array variable in script

Hi- I am returning output of an query into a array variable in my shell script. set -A DATE_RANGE `sqlplus -s **/**@** << EOF set termout off set echo off set serveroutput off set pagesize 0 set linesize 500 set heading off set verify off set feedback off select... (1 Reply)
Discussion started by: vputtas@gmail.c
1 Replies

4. Shell Programming and Scripting

awk question : system output to awk variable.

Hi Experts, I am trying to get system output to capture inside awk , but not working: Please advise if this is possible : I am trying something like this but not working, the output is coming wrong: echo "" | awk '{d=system ("date") ; print "Current date is:" , d }' Thanks, (5 Replies)
Discussion started by: rveri
5 Replies

5. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

6. Filesystems, Disks and Memory

iostat output vs TPC output (array layer)

Hi Guys, I've been having some arguments with my colleagues about one thing. Always my thought was that as as far as disk performance is concern by looking at the output of the iostat command (AIX) you would be able to identify if you have a hot disk and then by moving some files out that disk... (3 Replies)
Discussion started by: arizah
3 Replies

7. Shell Programming and Scripting

awk - Pre-populating an array from system command output

So, here's a scenario that requires the same logic as what I'm working on: Suppose that you have a directory containing files named after users. For awk's purposes, the filename is a single field-- something parse-friendly, like john_smith. Now, let's say that I'd like to populate an array in... (2 Replies)
Discussion started by: treesloth
2 Replies

8. Programming

C system() how to send the output to an array??

Hi, im in need if wisdom here guys... How could I store the output of commands like ping integrally directly into a array??? I'll be using system() to run the commands but how can I send the output to an array??? cuz I need to store it so that I can later copy the array's content to a buffer... (5 Replies)
Discussion started by: Jess83
5 Replies

9. Shell Programming and Scripting

Assign dscl output to variable as an array

Greetings folks, I am trying to assign the output of a dscl command (contains name<spaces>id) to a variable as an array. Currently I am piping the output into a tmp file, then reading the tmp file into an array, then parsing the array. I would like to bypass creating the tmp file portion of... (6 Replies)
Discussion started by: macnetdaemon
6 Replies

10. HP-UX

Moving AutoRaid array to another system

Hi All, I'm trying to move a disk array installed to one server has HPUX 11.0 to another server with the same OS version. But how can I make the other server recognize the disks with all the volume groups and logical volumes I have created. Please advice. Thank you. :) (3 Replies)
Discussion started by: ranias
3 Replies
Login or Register to Ask a Question