how to store output to a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to store output to a variable
# 1  
Old 08-28-2012
how to store output to a variable

I need some help:

1) I have a out put from a shell script, the out put looks like this:

Attempting privilege escalation using sudo ...


List backups for CLTST:

Start date Status Ret. Class Label
-------------------- ------------ ------------ --------------------------------
2012-07-30 07:40:03 SUCCESS Unlimited CLTST_20120730_073952_U
2012-08-07 12:07:42 SUCCESS Monthly CLTST_20120807_120727_M
2012-08-16 10:23:17 SUCCESS Hourly CLTST_20120816_102306_H

List clones for CLTST:

ID Status SID Host Label Comment
-------------------------------- ---------- ---------- -------------------- ------------------------------ --------------------
ff808081396ee3cf01396ee3d4e00001 SUCCESS T01 t01.h.vt.com C_CLTST_CM_P1_T01 Source: CLTST_20120816_102306_H Created: 20120828_151932 By: autovcptest
ff8080813945bdf6013945bdf98a0001 SUCCESS T03 t03.h.vt.com C_CLTST_CM_P2_T03 Source: CLTST_20120816_102306_H Created: 20120820_153341 By: auto
Ctl completed successfully.

I need to take the value t01 from the output and store it in a variable and use it in a shell/sql script and XMl file. How to do it?
# 2  
Old 08-28-2012
How about this ?
Code:
 perl -nle 'print $1 if (/(\w+)\.(\w+)\.(\w+)\.com/);' filename

# 3  
Old 08-29-2012
Thanks for the reply.
When i tried your code, i get this:

t01
t02

But i only want t01, so that i can use it in a variable for later use in a shell script

---------- Post updated at 10:16 PM ---------- Previous update was at 09:46 PM ----------

Thanks for the reply.
When i tried your code, i get this:

t01
t03

But i only want t01, so that i can use it in a variable for later use in a shell script

---------- Post updated at 10:44 PM ---------- Previous update was at 10:16 PM ----------

never mind. It worked.

Thank you for the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python - store output of command to a variable

I am trying to store output of python command in variable. Could you please help how I can do that ? For example I am executing the following command - "CentOS" in server_desc The output would be True or False I would like to store the output in a variable say outPut and use condition... (4 Replies)
Discussion started by: atanubanerji
4 Replies

2. Shell Programming and Scripting

how to store output into variable-in unix shell scripting

Hi, Output of "ps -o etime,time,pcpu,pmem,fname -C sbd-java" command is - Elapsed Time %cpu %MEM COMMAND 02:14:03 00:03:28 2.5 6.3 sbd-java Can anyone tell me, how to store the the value 2.5 in a variable? When I say echo $X where x is a variable then... (4 Replies)
Discussion started by: pspriyanka
4 Replies

3. Shell Programming and Scripting

store sqlplus output in variable

hi how can i store sqlplus output to a variable in sh script (not bash) Thanks MM (1 Reply)
Discussion started by: murtymvvs
1 Replies

4. Shell Programming and Scripting

date output store in variable problem

When I run following command date Output1 => Thu Sep 9 03:26:52 IST 2010 When I store in a varibale as a=`date` echo $a output2 => Thu Sep 9 03:27:02 IST 2010 The differnece is, it is trimming the space when I am storing the output in varibale. Output1 = Thu Sep 9 03:26:52 IST 2010... (2 Replies)
Discussion started by: pravincpatil
2 Replies

5. Shell Programming and Scripting

remove column and store output to a variable

Hello guys I need to run a script to remove the last column of different comma separated files. The problem is that the number of columns of my files will be different and I won't know that number every time i run my script. Is there any command I can use to remove the last column without... (7 Replies)
Discussion started by: loperam
7 Replies

6. Shell Programming and Scripting

store the output of "find" command in a variable?

I intend to find the path/full location of a file(filename given by user thru "read filenme") using "find" or any other command and then store it's output in a variable for some other processing. But struggling to put all things together (i.e finding the fully qualified location of that file and... (4 Replies)
Discussion started by: punitpa
4 Replies

7. Shell Programming and Scripting

ksh: How to store each output line into a different variable?

Example output: /tmp/generatelines.sh line1 line2 line3 line4 I want each output line assigned to its own variable, ie: "line1" --> $a "line2" --> $b "line3" --> $c "line4" --> $d Is this possible without writing to a temporary file? Thanks (4 Replies)
Discussion started by: ksheller
4 Replies

8. Shell Programming and Scripting

How to store the sql query's output in a variable

Hi, My requirement is : We are calling an sql statement from a UNIX session, and fetching data into some variables from a table .. now we are unable to access these variables from outside the SQL part. Please let me know how can I achieve this. Can you please share a code snippet which... (4 Replies)
Discussion started by: venkatesh_sasi
4 Replies

9. Shell Programming and Scripting

To store the output in a variable

Hi, I am getting the following error while executing the script. Please can someone throw some light where is the problem. Many thanks. ./check: temp: not found The directory related to SEP instance 4 does not exist. The script is as follows. SEP_APP="/scp/sepx/app... (2 Replies)
Discussion started by: Sudhakar333
2 Replies

10. UNIX for Dummies Questions & Answers

How to store output in variable when put in background

Hi, How do I store following command output: export RESULT=`date` & It works when I do : export RESULT=`date` But what I need is when command put it background, I also need that output going to RESULT variable. Is there any way ? Thanks Sanjay (1 Reply)
Discussion started by: sanjay92
1 Replies
Login or Register to Ask a Question