Passing Value from awk to shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing Value from awk to shell
# 1  
Old 08-06-2007
Network Passing Value from awk to shell

I'm writting a script to calculate the total files and number of files that have been generated but not able to access the value of qwk variable in Shell. Please suggest..


Script ::

cd /home/singhraa/tmp/scripts
count=0
total=`wc -l hk_jobs.txt` #total number of files
echo $total
for i in `cat hk_jobs.txt`
do
autorep -j $i | grep EQDEL | awk '{if ($5 == "SU"); count=$($count) + 1; print count}' # check how many files processed
echo $count #trying to access the value here but Smilie
if [ $count -eq $total ]
then
echo "All files done"
fi
done
# 2  
Old 08-06-2007
This is your code corrected, but I'm not sure what you're trying to do... Maybe there's an error in the logic.

Code:
cd /home/singhraa/tmp/scripts
total=`wc -l hk_jobs.txt | awk '{ print $1; }'`
echo "$total"
for i in `cat hk_jobs.txt`
do
   count=`autorep -j $i | grep EQDEL | awk '{ if ($5 == "SU"); c++; } END { print c; }'` 
   echo "$count"
   if [ "$count" -eq "$total" ] 
   then
      echo "All files done"
   fi
done

Bye Smilie
# 3  
Old 08-06-2007
Code:
autorep -j $i | awk -v var=$total '/EQDEL/  { if ($5 == "SU") { count++ } if ( var == count ) { print "somemessage-somecomparison" } }'

# 4  
Old 08-06-2007
You can try something like this:
Code:
cd /home/singhraa/tmp/scripts
count=0
total=$(wc -l hk_jobs.txt) #total number of files                                                                                            
echo $total
for i in `cat hk_jobs.txt`
do
sum=$(autorep -j $i | awk '/EQDEL/ {if ($5 == "SU"){print 1}else{print 0}}')                                                                 
count=$(( count + sum ))
echo $count #trying to access the value here but
if [ $count -eq $total ]
then
echo "All files done"
fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing Shell Variable to awk

Hello All, May i please why my shell variable is not getting passed into awk script. #!/bin/bash -vx i="1EB07C50" /bin/awk -v ID="$i" '/ID/ {match($0,/ID/);print substr($0,RSTART,RLENGTH)}' /var/log/ScriptLogs/keys.13556.txt Thank you. (1 Reply)
Discussion started by: Ariean
1 Replies

2. UNIX for Dummies Questions & Answers

Passing Global Shell variables to awk

Hi All, Iam trying to pass global shell variables and is not working Main script is like below CYEAR=`date +"%y"` CFYEAR=`date +"%Y"` CMONTH=`date +"%m"` if then PMONTH=12 PYEAR=`expr $CYEAR - 1` PFYEAR=`expr $CFYEAR - 1` else PMONTH=`expr... (6 Replies)
Discussion started by: baanprog
6 Replies

3. Shell Programming and Scripting

Passing values from awk to shell variable

I am writing a script where I need awk to test if two columns are the same and shell to do something if they are or are not. Here is the code I'm working with: @ test = 0 ... test = `awk '{if($1!=$2) print 1; else print 0}' time_test.tmp` #time_test.tmp holds two values separated by a space... (3 Replies)
Discussion started by: Malavin
3 Replies

4. Shell Programming and Scripting

Passing awk variables to shell

Hi. I need to parse file and assign some values to variables, right now i do like below MYHOMEDIR=`awk '/Home/ {print $NF}' output.txt` MYSHELL=`awk '/Shell/ {print $NF}' output.txt` PRGRP=`awk '/Primary/ {print $NF}' output.txt` SECGRP=`awk '/Second/ {print $NF}' output.txt` In this... (10 Replies)
Discussion started by: urello
10 Replies

5. Shell Programming and Scripting

Passing shell variable to awk script

I want to pass a shell variable to awk script : # cat file PSAPSR3 3722000 91989.25 2 98 PSAPSR7 1562000 77000.1875 5 95 PSAPUNDO 92000 4087.5625 4 96 #... (8 Replies)
Discussion started by: Reboot
8 Replies

6. UNIX for Dummies Questions & Answers

Passing Shell Variables to an awk command

Hello, I have two files File1 & File2. File1 76 135 136 200 250 345 .... File2 1 24 1 35 1 36 1 72 .... I want to get all the values form File2 corresponding to the range in File 1 and feed it to a program. Is the code below right? Can I pass shell variables to awk in this... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

7. UNIX for Dummies Questions & Answers

Passing a Shell Variable to awk

Hello, I have a file with 4 columns. An arbitrary example is shown below: a Tp 10 xyz b Tq 8 abc c Tp 99 pqr d Tp 44 rst e Tr 98 efg Based on the values in col 2 and col 3, I will execute another program. I have been running this:... (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

8. UNIX for Dummies Questions & Answers

Passing Shell Input to AWK

I am trying to search a log for a particluar pattern listing the total # of occurences in the end. I thought using a shell script for input then calling awk to search for the paramters specified. I want the script to be usable acorss envs. Code: #! /usr/bin/bash # get the variables... (5 Replies)
Discussion started by: wawa44oz
5 Replies

9. Shell Programming and Scripting

Passing a variable to awk while in a shell for loop

I am a newbie to awk and c programming, however am not a unix newbie. However, I do need help with a kshell script I am writing. It is almost complete, the last step is killing me. Any help would be greatly appreciated. What I am trying to do is cat a text file that has usernames. Then, using... (2 Replies)
Discussion started by: synergy_texas
2 Replies

10. Shell Programming and Scripting

passing awk variable to the shell script

hi; i have a file containing lines like: 1|1069108123|96393669788|00963215755711|2|0|941||;serv:Pps6aSyria;first:0;bear i want to extract the second, third and fourth record of each line and store it in a file ";" seperated this is what i wrote while read line do ... (3 Replies)
Discussion started by: bcheaib
3 Replies
Login or Register to Ask a Question