control is not going inside the awk ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting control is not going inside the awk ?
# 1  
Old 06-22-2009
control is not going inside the awk ?

Hi


the control is not going inside the awk..
/u/bin/psg -t "pts/tC" |/bin/grep -e "ServTest" | /bin/grep -v "root"
run separately in the command line lists the running process..

why is the code inside the awk not being being executed?
can anyone tell what went wrong.

Code:
 
list=`/u/Test/programs`;
/u/bin/psg -t "pts/tC" |/bin/grep -e "ServTest" | /bin/grep -v "root" | awk -v mode=$0 '{
        kill = 0
        pid=$2
        uid=$1
        cmd_name=($5 ~ /^[A-Z]/)? $9:$8
        print "I am in between ffff"
        for(pgm in list)
        {
                pgm="de$pgm";
                if (pgm == cmd_name)
                {
                        kill = 1;
                }
        }
        if (kill == 1)
        {
                if (mode == "kill")
                {
                     print ("killing %s with %d \n",cmd_name,pid);
                     system("/u/bin/date>> /u/Test/Log")
                     print " " $0 >> "/u/Test/Log"
                     op="/u/bin/remsh " hn " -l " user "; u/bin/kill -9 " pid ">> "/u/Test/Log";
                     system(op)
                }
        }#end if
  }'

regards

Last edited by Anteus; 06-22-2009 at 07:10 AM..
# 2  
Old 06-22-2009
mode=$0 ###won't work
what is list?? is it an array??
echo won't work inside awk
there are many problems....
# 3  
Old 06-22-2009
Quote:
Originally Posted by vidyadhar85
mode=$0 ###won't work
what is list?? is it an array??
echo won't work inside awk
there are many problems....

ooh i am sorry about echo . my mistake. after correcting it printf is printing so it means code inside awk is executing..

why the printf inside for loop is not printing list has two lines.
why would not the mode=$3 work i am using it with the awk -v option , which provides initiation and assignment of the shell variable. so i think its fine. please correct me if i am wrong.

and list is a file containing names of programs.

regards

Last edited by Anteus; 06-22-2009 at 07:15 AM..
# 4  
Old 06-22-2009
no you can't assign $0 with -v option unless 0 is your variable name
check that with simple example
and you can't use a file just like that in awk
please read the awk man page once
# 5  
Old 06-22-2009
Quote:
Originally Posted by vidyadhar85
no you can't assign $0 with -v option unless 0 is your variable name
check that with simple example
and you can't use a file just like that in awk
please read the awk man page once
okk
yeah $0 is argv[0]

---------- Post updated at 04:04 PM ---------- Previous update was at 04:00 PM ----------

please delete this thread if you can there are lot of silly mistakes in this code..which i am seeing now..

and can you give me some links where i can find how to read contents of a file inside awk ..

thanks and regards
# 6  
Old 06-22-2009
Quote:
Originally Posted by Anteus
okk
yeah $0 is argv[0]

---------- Post updated at 04:04 PM ---------- Previous update was at 04:00 PM ----------

please delete this thread if you can there are lot of silly mistakes in this code..which i am seeing now..

and can you give me some links where i can find how to read contents of a file inside awk ..

thanks and regards
Here's something to start with!
# 7  
Old 06-22-2009
Quote:
Originally Posted by vgersh99
Here's something to start with!
I never knew to type

dablu dablu dablu dot google dot kom..

thanks for showing me a start a decade back Smilie

regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed inside awk

What I want to do is delete everything upto the last underscore (_) in column 2. awk '{ $2=$(echo $2 | sed 's/.*_//'); print $0}' Sed works fine if I echo the string into it, this doesnt work inside awk. What am I doing wrong? Similarly, how do I store the substring starting with a... (4 Replies)
Discussion started by: senhia83
4 Replies

2. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Shell Programming and Scripting

Split using AWK - out file name control

Hi Gurus, I am using following code to split a big file into pieces. awk '!((NR-1)%ln){close(f);f=name i++}{print>f}' i=1 name=my_file ln=25000 main_file The output that is produces is something like this - my_file2 my_file1 my_file4 my_file3 my_file5 my_file7 my_file6 my_file9... (3 Replies)
Discussion started by: mukesh.lalwani
3 Replies

4. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. UNIX for Dummies Questions & Answers

awk NR==FNR output control

Hi Guys, I have two files: f1: A B C D E F G H f2: A X Y Z f1 has 48000 lines, and f2 has 68. I have been matching f1 $3 to f2 $1, and getting f3: A A B C D E F G I would like f3 too look like this: A X Y Z A B C D E F G (2 Replies)
Discussion started by: heecha
2 Replies

6. Shell Programming and Scripting

help: Awk to control number of characters per line

Hello all, I have the following problem: My input is two sorted files: file1 >1_19_130_F3 T01220131330230213311013000000110000 >1_23_69_F3 T01200211300200200010000001000000 >1_24_124_F3 T010203113002002111111200002010 file2 >1_19_130_F3 24 18 9 18 23 4 11 4 5 9 5 8 15 20 4 4 7 4... (9 Replies)
Discussion started by: DerSeb
9 Replies

7. Shell Programming and Scripting

awk inside another awk statement

hi all, i have two files 1) a.txt one two three 2) abc "one" = 10 pqr "three" = 20 345 "two" = 0 this is what i want in third file (3 Replies)
Discussion started by: shishirkotkar
3 Replies

8. UNIX for Dummies Questions & Answers

Awk inside Awk expression

Hi, It can be used awk inside other Awk?. I need to get another text processing while other text process. Thank you. (2 Replies)
Discussion started by: pepeli30
2 Replies

9. Shell Programming and Scripting

Using variable inside awk

I am trying to print the lines with pattern and my pattern is set to a variable express awk '/$express/{where=NR;print}' test2.log I am not getting any data even though i have the data with the pattern. Can seomeone correct me with the awk command above? (20 Replies)
Discussion started by: rdhanek
20 Replies

10. Shell Programming and Scripting

Trim inside awk

Hi all, I am using qwk to parse the logfile. The code like awk ' { if($0 > " ") { MSISDN=substr($0,1,10) HOUR=substr($0,11,6); ID_SA_SOURCE=substr($0,17,18); ID_SA_DEST=substr($0,35,18); ... (3 Replies)
Discussion started by: subin_bala
3 Replies
Login or Register to Ask a Question