Redirect to a Variable? Or is it cmd cap?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Redirect to a Variable? Or is it cmd cap?
# 1  
Old 11-22-2008
Redirect to a Variable? Or is it cmd cap?

Hi,

Im reading an ANSI text file and greping for a pattern. Then i cut what i dont need from that pattern. So now i just have what i need. What i have now just so happens to be a constant integer. How can i save this integer in a varaible? Or do i use command capture in some form?

Code:
cat Hello.txt | egrep "That One Pattern" | awk '{print $NF}'

Also..This command might be really useful to me, i just dont understand it.
Since maybe i can use these varaibles with the one i would like to store above..

Code:
awk '{for (i=1; i<=NF; i++) s=s+$i}; END{print s}'

# 2  
Old 11-22-2008
Code:
cat Hello.txt | egrep "That One Pattern" | awk '{print $NF}'

I have a value in that code. But i cant add it to anything. Awk has its own language so i cant change the NF variable to preform any arithmetic with other command lines...Not that i could of anyway. right?

So i used another method:
Code:
cat Hello.txt | egrep "That One Pattern" | cut -d':' -f2

That code has a value as well. How would i store it in a varaible??

Code:
Value=Hello.txt | egrep "That one Pattern" | cut -d':' -f2

har har har. But i really dont know.


-----------------------------------------------
Everybody looks cool at blacklight parties
execpt for me, because i was under the impretion
that the mustard stain came out...
------------------------------------------------
# 3  
Old 11-22-2008
Dont undestand what you want...
Is it assign to a variable the result of one of your commands above?
in ksh you would do so like that:
Code:
VAL1=$(cat Hello.txt | egrep "That One Pattern" | awk '{print $NF}')
#to check
echo " VAL1 = " $VAL1

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect Variable Value to a File

I have shell script generate.sh that has var="HP-UX" I am following example 19-8 in the below document. Here Documents The output.txt is generated however I want the value of variable var to be reflected in the contents of the output.txt file cat <<'EOF' #!/bin/bash connect("Welcome... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Problem assigning cmd output to variable then using in IF statement

Hi, I'm using the bourn shell on a Sun Solaris Unix system. I am relatively new to UNIX scripting so please bear with me... I'm having a couple issues: 1) I need to have a variable $FSIZE set with the output of a command each time the script runs. (the command looks for a file and... (8 Replies)
Discussion started by: dqrgk0
8 Replies

3. Shell Programming and Scripting

set output of linux cmd as a variable in .exp

I am trying to make a script to take commands from a .txt file ( line by line) and pass it using send ( used in another function ) what i am trying to achieve is : set nol "`grep '' ${exp_path2}/cmdlist.txt | wc -l `" as in shell script nol=`grep '' $exp_path2/cmdlist.txt | wc -l` ... (0 Replies)
Discussion started by: dixyantar
0 Replies

4. Shell Programming and Scripting

How to input the return value (1 or 0) ping cmd to a variable

Hi I would like to ask about my plan script I have this several workstation want to monitor and execute a command without logging it we use "rsh $host "<command>" i create csh script using foreach to loop my several workstation, my problem with the rsh command is if it encounter a... (3 Replies)
Discussion started by: jao_madn
3 Replies

5. Shell Programming and Scripting

how2 shell cmd into variable

How do I place the result of a shell command into a variable. I would like to save the pwd in $DIR. I tried... pwd | $DIR $DIR < pwd DIR=pwd thanks! jz (2 Replies)
Discussion started by: jwzumwalt
2 Replies

6. Shell Programming and Scripting

redirect cat to variable

hello just i saw a really strange for cat i have file (file1) contains line /home/rajiv/proj1/*.txt now applied a commonds DDPATH="$(cat file1)" echo $DDPATH it shows all the txt files in that folder like /home/rajiv/proj1/read1.txt /home/rajiv/proj1/read2.txt... (7 Replies)
Discussion started by: shailesh_arya
7 Replies

7. Shell Programming and Scripting

after grep i want to redirect it to some variable

for the below grep -i $1 "${logdir}"* | grep -i adding | grep -iv equation | tail -1 | cut -d ':' -f 1 the result of the grep i want to redirect into some variable, i tried to do veri=grep -i $1 "${logdir}"* | grep -i adding | grep -iv equation | tail -1 | cut -d ':' -f 1 but it is... (2 Replies)
Discussion started by: mail2sant
2 Replies

8. 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

9. UNIX for Dummies Questions & Answers

Redirect to variable

how do you redirect stdout into a variable. whenever I try I get an ambiguous redirect error :( I am trying to validate some user input and failing miserably. cal $MONTH $YEAR | grep -c "$DAY" if the above is 1 then it is valid if 0 then not valid. I have been trying to redirect the output... (2 Replies)
Discussion started by: MrAd
2 Replies
Login or Register to Ask a Question