pass an awk variable to kill


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pass an awk variable to kill
# 1  
Old 10-09-2011
pass an awk variable to kill

Does anyone know of a way to do something similar to this with awk and kill? I want to create the variable in awk and pass that variable to kill.

Code:
ps -ef | grep -i chromium | awk '{$2=x}' | kill -9 $x 2>/dev/null

# 2  
Old 10-09-2011
You don't need to pass variable.

Code:
ps -ef | grep -i chromium | awk '{print $2}' | xargs kill -9



BTW, Is it really necessary to use SIGKILL (-9) ?
Also, Your command would also list the grep invocation I guess.
# 3  
Old 10-09-2011
Is killing the chromium is all you want to do? If so try this
Code:
pgrep chromium | xargs kill -9

--ahamed
# 4  
Old 10-10-2011
Quote:
Originally Posted by anchal_khare
You don't need to pass variable.

Code:
ps -ef | grep -i chromium | awk '{print $2}' | xargs kill -9

BTW, Is it really necessary to use SIGKILL (-9) ?
Also, Your command would also list the grep invocation I guess.
For some programs yes Smilie.

xargs is the easy way :P. I wanna do it the complicated way Smilie.

Quote:
Originally Posted by ahamed101
Is killing the chromium is all you want to do? If so try this
Code:
pgrep chromium | xargs kill -9

--ahamed
Without xargs please Smilie. I wanna do it the complicated way Smilie.
# 5  
Old 10-10-2011
Quote:
Originally Posted by COKEDUDE
I wanna do it the complicated way Smilie.

Without xargs please Smilie. I wanna do it the complicated way Smilie.

The most complicated way is try and discover yourself. Isn't it? Smilie
# 6  
Old 10-10-2011
If the OP decides to use something simpler later, some OS provides pkill Smilie

Code:
pkill <process_name>

# 7  
Old 10-10-2011
then this one?
Code:
kill -9 `pgrep chromium`

or

Code:
die chromium die!

SmilieSmilieSmilie

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Pass shell Variable to awk

Hello, May i please know how do i pass the shell variable to awk expression in the below script. It is returning null #!/bin/bash UNINUM=720922 UNINUM_DESC=`awk -F'|' -v UNINUM=$2 '/UNINUM/ {print $4}' datafile` echo $UNINUM_DESC datafile 4|First|720194|asdasdad 4|First|720735|asdasdsa... (8 Replies)
Discussion started by: Ariean
8 Replies

2. UNIX for Dummies Questions & Answers

How to pass a variable from shell to awk

I know this topic has been dealt with previously, but the solutions I've seen don't work for me apparently. I need to pass a variable defined in the shell to one in awk: $ echo $var1 3 $ cat aaa aaa 1 bbb 2 ccc 3 ddd 4 eee 5I've tried this, without success: $ awk... (2 Replies)
Discussion started by: metaltree
2 Replies

3. Shell Programming and Scripting

how to pass variable in NR function used in awk command?

Hi I want to pass variables with the NR function in awk command. test_file1 is input file having 500 records. var1=100. var2=200 awk -F" " 'NR >= $var1 && NR <= $var2' test_file1 > test_file2. My end result should be that test_file2 should have records from line number between... (2 Replies)
Discussion started by: Nishithinfy
2 Replies

4. Shell Programming and Scripting

ksh variable pass to awk

I'm trying to store the response from a nawk command inside of a ksh script. The command is: text=$(nawk -F: '$1 ~ /${imgArray}/ {print $2}' ${etcDir}/captions.txt) From what I can tell, the imgArray variable is not being expanding when it is inside the single quote ('). Is there something I... (4 Replies)
Discussion started by: meman1188
4 Replies

5. Shell Programming and Scripting

How to pass a Awk variable to another script

Read parameter from a text file with one line which stored the date value like 20080831; below is the awk command I used gawk -F, "{getline RunDate;print $RunDate" text file When print $RunDate, it display 20080831 Would like to pass this variable to another script to use but not... (6 Replies)
Discussion started by: cbauw
6 Replies

6. Shell Programming and Scripting

Is it possible to pass variable from awk to shell back

I am passing a varaible to from Shell to awk then I am doing some maniplation for that variable inside awk. I want that maniplated variable value back to shell , Is this possible .Please let me know. (12 Replies)
Discussion started by: unishiva
12 Replies

7. Shell Programming and Scripting

Pass script variable value to AWK

HI all, some more mistery about AWK, I hope you can help me out: 1) I have a normal ksh script and sometime I call awk command. I set some variables in the script and I would like to use them up within AWK as well. Unfortunately AWK seems to forget all the variable values outside of its own... (1 Reply)
Discussion started by: BearCheese
1 Replies

8. UNIX for Dummies Questions & Answers

How do I pass a variable to awk?

I have an awk statement where I Need to pass an environment variable but I cannot get it to work: My evironment varible examples below: $FILE1=/dev/fs/file.new $FILE2=/dev/fs/file.old Code below: awk -F"|" ' BEGIN { while( getline < "$FILE1" ) { arr=1 } } arr != 1 { print } '... (12 Replies)
Discussion started by: eja
12 Replies

9. Shell Programming and Scripting

How to pass a variable to Awk ?

I am trying to pass 2 shell variable's ("START" and "END") define earlier in the script to this awk statement, but i can't seem to pass it on. PLs help. set START = xxxx set END = yyyy set selected_file = `awk '/$START/,/$END/' filename` (24 Replies)
Discussion started by: Raynon
24 Replies

10. UNIX for Dummies Questions & Answers

pass variable to awk

i would like to pass a variable to awk wherein the variable comes from external loop. i tried this... let x=0 until test $x -eq 32 do cat file | awk '{ print $1 , "Number" , $($x) }' >> output done thanks, (4 Replies)
Discussion started by: inquirer
4 Replies
Login or Register to Ask a Question