Store result variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Store result variable
# 1  
Old 11-26-2015
Store result variable

Friends have the following problem:

Code:
cat $PATH_DAT/mr.txt | nawk  'BEGIN {
                CantPnt=0;
                NumReg=0;
                FS="|"
              }
              {
                NumReg++
                CantPnt=CantPnt+int($2)
              }
END{
        printf ("%d|%d",NumReg,CantPnt)
}
' > TmpValida.Tmp

this perfect function code without problem and the result is in the file TmpValida.Tmp

you need to do is save the result in a variable and not in the file
# 2  
Old 11-26-2015
Hello tricampeon81,

Could you please try following and let me know if this helps you. I haven't tested it though.
Code:
VAR=`nawk  'BEGIN {CantPnt=0;NumReg=0;FS="|"} {NumReg++; CantPnt=CantPnt+int($2)} END{printf ("%d|%d",NumReg,CantPnt)}' $PATH_DAT/mr.txt`

You could then print the value of variable named VAR by doing echo $VAR.

Thanks,
R. Singh
# 3  
Old 11-26-2015
Quote:
Originally Posted by RavinderSingh13
Hello tricampeon81,

Could you please try following and let me know if this helps you. I haven't tested it though.
Code:
VAR=`nawk  'BEGIN {CantPnt=0;NumReg=0;FS="|"} {NumReg++; CantPnt=CantPnt+int($2)} END{printf ("%d|%d",NumReg,CantPnt)}' $PATH_DAT/mr.txt`

You could then print the value of variable named VAR by doing echo $VAR.

Thanks,
R. Singh
this function but the result is not the same to remove the CAT

# 4  
Old 11-26-2015
Please show the differences, then!
This User Gave Thanks to RudiC For This Post:
# 5  
Old 11-26-2015
Quote:
Originally Posted by tricampeon81
this function but the result is not the same to remove the CAT
I am so sorry!!!
I have not seen that replaced the cat at the end !!
function perfect !!!!!
was what nesecitaba !!!

This product is perfect !!!!

---------- Post updated at 08:00 AM ---------- Previous update was at 07:59 AM ----------

I tried it and it works perfect

---------- Post updated at 08:33 AM ---------- Previous update was at 08:00 AM ----------

hat friendly look that code this variable turned keeps this value:
Code:
Nawk `VAR = 'BEGIN {CantPnt = 0; SET- # = 0; FS =" | "} {SET- # ++; CantPnt CantPnt + = int ($ 2)} END {printf ("% d |% d" SET- #, CantPnt)} '$ PATH_DAT / mr.txt`

Code:
Departure:

VAR = 10 | 500

now I need to keep the 10 in a variable and another variable 500 I tratandod and use split but not me
# 6  
Old 11-26-2015
With a recent bash, you can try a here string:
Code:
IFS="|" read VAR1 VAR2 <<< $(nawk '... ' ...)

or a here document:
Code:
IFS="|" read VAR1 VAR2 << EOF
 $(nawk '... ' ...)
EOF

---------- Post updated at 14:56 ---------- Previous update was at 14:55 ----------

You can drop the IFS definition if you don't print the "|" in the awk output but use " " instead.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to store result in variable for other lines in script to use

I can not figure out how to capture the $filename variable store by the bash. #!/bin/bash # oldest folder stored as variable for analysis, version log created, and quality indicators matched to run dir=/home/cmccabe/Desktop/NGS/test find "$dir" -maxdepth 1 -mindepth 1 -type d -printf... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Different cmd to execute and based on some pattern parse it and then store result in xlx format

Hi I have a different requirement, I need to run some application on my device from a file app_name.txt one by one which is like this: /usr/apps/email /usr/apps/message /usr/apps/settings after each app while it is running I need to execute again one cmd like ps -ef |grep... (2 Replies)
Discussion started by: Sanjeev Roy
2 Replies

3. Shell Programming and Scripting

How to store result of grep into a variable?

In a directory i have a file *output* whose contents are changing for every simulation. zgrep "trace file is" *output* | zgrep g o/p: trace file is Int_01.1352176388z4f56ec33.0.trace.gz I want to extract "Int_01.1352176388z4f56ec33.0.trace.gz" from the above result into a variable. i... (2 Replies)
Discussion started by: twistedpair
2 Replies

4. Shell Programming and Scripting

Assign zero to strings that don't appear in block, store result in AWK array

Hi to all, I have this input: <group> <x "2">Group D</x> <x "3">Group B</x> <x "1">Group A</x> </group> <group> <x "1">Group E</x> <x "0">Group B</x> <x "1">Group C</x> </group> <group> ... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

5. Shell Programming and Scripting

Search file for string and store last result to variable

Hi, I'm trying to search a text file for a string: "energy(sigma->0)=". To do so, I executed the grep command, which returned many matches, for example: energy without entropy = -112.16486170 energy(sigma->0) = -112.16520778 energy without entropy = -112.16488936 ... (5 Replies)
Discussion started by: gwr
5 Replies

6. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

7. Shell Programming and Scripting

Embed commands into an expr command? (so I only store result)

Hi Can I thank the advice I've received on here previously, working examples are helping me teach myself BASH fairly quickly and I've written some pretty complex scripts now (even if I do say so myself). Anyhooo..... I'm writing a script that handles lots of text files and does various... (3 Replies)
Discussion started by: Bashingaway
3 Replies

8. Shell Programming and Scripting

Find diff bet 2 files and store result in another file

Hi I want to compare 2 files. The files have the same amount of rows and columns. So each line must be compare against the other and if one differs from the other, the result of both must be stored in a seperate file. I am doing this in awk. Here is my file1: Blocks... (2 Replies)
Discussion started by: ladyAnne
2 Replies

9. Shell Programming and Scripting

Prase a file and store and result to an array

Dear all, I have a file having the following formats: ThreadFail=Web1=1234 ThreadFail=Web2=2345 ThreadFail=Web3=12 ConnectionFail=DB1=11 ConnectionFail=DB2=22 The number of lines will be different from every time . How can I parse the file and store the result to an a array inside... (6 Replies)
Discussion started by: youareapkman
6 Replies

10. Shell Programming and Scripting

How to store query multiple result in shell script variable(Array)

:) Suppose,I have one table A. Table A have one column. Table A have 10 rows. I want this 10 rows store into shell script variable. like #!/bin/ksh v_shell_var=Hi here in call oracle , through loop How can I store table A's 10 rows into v_shell_var (Shell Script Array). Regards, Div (4 Replies)
Discussion started by: div_Neev
4 Replies
Login or Register to Ask a Question