cree a variable from a commande result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cree a variable from a commande result
# 1  
Old 11-13-2006
cree a variable from a commande result

Hi everybody

I m looking the put the result of a commande to a Variable
i explain


here is my command:

cat sortie | grep "^[1-9999]"| awk '{ print $1}'
15


sortie is a text file
I want to put the result of command in a variable X

and the end i would like

echo $X
15

I hope you understand what i want to do, sorry for my english
I m french

Last edited by kykyboss; 11-13-2006 at 10:38 AM..
# 2  
Old 11-13-2006
With KSH and BASH:
Code:
X=$(awk '/^[1-9999]/ {print $1}' sortie)

With SH, KSH and BASH:
Code:
X=`awk '/^[1-9999]/ {print $1}' sortie`


Jean-Pierre.
# 3  
Old 11-13-2006
thank i found it


x=`cat sortie | grep "^[1-9999]"| awk '{ print $1}'`


i m a beginner
# 4  
Old 11-13-2006
thank aigle that work problem close
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Store result variable

Friends have the following problem: cat $PATH_DAT/mr.txt | nawk 'BEGIN { CantPnt=0; NumReg=0; FS="|" } { NumReg++ CantPnt=CantPnt+int($2) } END{ printf... (5 Replies)
Discussion started by: tricampeon81
5 Replies

2. UNIX for Dummies Questions & Answers

I save the result in a variable

I have friends that this command worked perfectly, but I would like to save the result in a variable, which I have not achieved var=prueba.txt echo $var | cut -d "." -f 1 prueba I need to do this but does not work me salida=echo $var | cut -d "." -f 1 echo "result:$salida" ... (8 Replies)
Discussion started by: tricampeon81
8 Replies

3. Shell Programming and Scripting

Result of 'cut' into variable

Hello, I would like to have a result of a cut-command in a variable. The file "t.dat" has the following content: Company 001.239879123.OB1X.672W12.STS UNOLD.001.02 My bash-script: Header="" Header=$(cut -c1-160 t.dat | head -1) echo $Header ... (9 Replies)
Discussion started by: API
9 Replies

4. Shell Programming and Scripting

How to combine two variable result?

Hi, i have two variables i.e lck_ckm_customer=ckm_customer and(present in some script A) table=ckm_customer(present in script B) in script B i am executing this part if ; then --- ---- ---- fi Now, while comparing in my log file i am getting this result if but i... (2 Replies)
Discussion started by: gnnsprapa
2 Replies

5. Shell Programming and Scripting

result in variable

Hi all, I'll try to get a result from a search with "awk" into a variable. It works for those examples: findfirstline=`awk 'BEGIN{ mycount = 1 } { if(mycount == 1 && /^Video/){ row=NR; print row; mycount = 0; }}' ${i}` findlastline=`awk '/^Video/ {row=NR} END{print row}' ${i}` But it... (6 Replies)
Discussion started by: tempestas
6 Replies

6. UNIX for Dummies Questions & Answers

Pb commande externe \r

J'ai un soucis avec une commande externe... la voici : #!/bin/bash/ mkdir lol mkdir not sleep 2 mkdir glop Mon bash l'éxécute (déjà ça :rolleyes:) à sa façon..... Je me retrouve avec non pas 3 dossiers lol, not et glop. Mais les dossiers : lol?, not? et glop (oui ! un de bon !!!!!). Et, une... (9 Replies)
Discussion started by: sluvah
9 Replies

7. Shell Programming and Scripting

Assign result to variable

Hi friends, firstly, i can run following expression and i took 100 value. sqlplus -s username/password@TTTEST @umt.sql umt.sql exists "select t.deger from parametre t where t.id=30". result of this query =100 i need to assign this value(100) to variable(for example x... (2 Replies)
Discussion started by: temhem
2 Replies

8. Shell Programming and Scripting

sum two numbers on a grep commande with the parameter -n

Hello, I want to know how i can sum two numbers in a grep command with the parameter -n. this code return line number and the line who have the "pattern" : *\).*/\1/p') ] but now i want to suw *\).*/\1/p')] with 1 to have the next line: *\).*/\1/p')] + 1 : it can't work. Thanks you (4 Replies)
Discussion started by: samara80
4 Replies

9. AIX

commande mailx : spaces in the title

Hello ! I use mailx to send emails. I use it like that mailx -s $titleMail $mailAdr < BODY_MAIL.txt The problem , is if i have some spaces in the variable titleMail it is considered by the command mailx like other mail adress to send the mail. Anyone would have a suggestion... (1 Reply)
Discussion started by: comboDev
1 Replies

10. UNIX and Linux Applications

How to get a result of a cmd into variable?

Hi , I am trying following . I need to get a result of an autosys cmd into a unix variable. The autosys cmd is autostatus -G jpm_day_today Please help me in storing the value returned by this cmd into a unix variable. Appreciate your time to read this post. (1 Reply)
Discussion started by: manchau
1 Replies
Login or Register to Ask a Question