how to display column value in a row with space as delimeter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to display column value in a row with space as delimeter
# 1  
Old 07-05-2010
how to display column value in a row with space as delimeter

Hi
I need to write a small script to kill the process id of particular job in one shot ,
Example
Code:
> ps
 PID TTY       TIME COMMAND
 16280 pts/70    0:00 sh
 16278 pts/70    0:00 rlogind
 16197 pts/70    0:00 ps
 1234  pts/70    0:00  runflow
 2341  pts/70    0:00  runflow
 12673 pts/70    0:00  runflow.

I need to kill runflow process id .Everytime to write all the prcosess id's of runflow is quite tedious as sometimes there are lot of runflow scripts running .
Code:
kill 1234 2341 12673

i tried to do but i am stuck ..
Code:
ps |grep "runflow" | cut -f2 -d' '

This will show the process id of run jobs , but i need all this to be arranged in a row and then i need to kill the process.
Please suggest .

Moderator's Comments:
Mod Comment Use code tags please.

Last edited by zaxxon; 07-05-2010 at 02:44 AM.. Reason: code tags
# 2  
Old 07-05-2010
Hi
Are you looking for something like this:

Code:
$ ps | awk '/runflow/{print "kill -9 ", $1}'
kill -9  1234
kill -9  2341
kill -9  12673

This output can be copied to a file, and you can run the file or you can run the command itself in backticks.

Guru.
# 3  
Old 07-05-2010
Code:
ps -ef| awk '$NF ~ /runflow/ {print $2}'| xargs kill

Can also use the system() function inside awk to issue the kill. xargs would be redundant then.
# 4  
Old 07-05-2010
Code:
pkill runflow

# 5  
Old 07-05-2010
Why not just use "killall runflow"?

edit: or pgrep
Code:
pgrep runflow | xargs kill


Last edited by fubaya; 07-05-2010 at 03:02 AM..
# 6  
Old 07-05-2010
IMO the awk solutions just like greps need to use /[r]unflow/ to prevent the awk process itself from being killed.

---------- Post updated at 08:10 ---------- Previous update was at 08:06 ----------

Quote:
Originally Posted by fubaya
Why not just use "killall runflow"?

edit: or pgrep
Code:
pgrep runflow | xargs kill

Not all systems have killall and/or pgrep/pkill. Be careful where you run the killall command as it has a different meaning (oops) on at least an HPUX system:
killall(1M)

Last edited by Scrutinizer; 07-05-2010 at 03:16 AM..
# 7  
Old 07-05-2010
Quote:
Originally Posted by fubaya
Why not just use "killall runflow"?
On AIX for example killall is not the same as on Linux. That's why it could be a reason to use it not for this purpose.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace space and tab to pipe delimeter

I have file like below abc 12 34 45 code abcdef 451 1 4 code ghtyggg 4 56 3 code I need to change this to abc|12|34|45|code| abcdef|451|1|4|code| ghtyggg|4|56|3|code| I tried replace space with | in sed ... but in the middle some row has... (7 Replies)
Discussion started by: greenworld123
7 Replies

2. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

3. Shell Programming and Scripting

how to remove tab space only in the column of a specific row

Hi, I need help to remove tab delimited space in the $2 of a specific row. My file is like this:- file1.txt No_1 4 139 156 No_1 5 161 205 No_4 91 227 212 No_19 254 243 263 No_19 645 249 258 No_19 101 2492 2635 No_90 8 277 288... (5 Replies)
Discussion started by: redse171
5 Replies

4. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

5. UNIX for Dummies Questions & Answers

How do you delete cells from a space delimited text file given row and column number?

How do you delete cells from a space delimited text file given row and column number? Letś say the row number is r and the column number is c. Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

6. Shell Programming and Scripting

Count the delimeter from a file and delete the row if delimeter count doesnt match.

I have a file containing about 5 million rows, in the file there are some records which has extra delimiter at random position. (we dont know the positions), now we have to Count the delimeter from each row and if the count of delimeter is not matching then I want to delete those rows from the... (5 Replies)
Discussion started by: Akumar1
5 Replies

7. Shell Programming and Scripting

Moving data from a specified column/row to another column/row

Hello, I have an input file like the following: 11_3_4 2_1_35 3_15__ _16989 Where '_' is a space. The data is in a table. Is there a way for the program to prompt the user for x1,y1 and x2,y2, where x1,y1 is the desired number (for example x=6 y=4 is a value of 4) and move to a desired spot... (2 Replies)
Discussion started by: jl487
2 Replies

8. UNIX for Dummies Questions & Answers

display column in a row

how can i display every column in a row individually........ i vauguely remmeber something like echo $1 $2 etc.......but i dont remmeber properly......so is there anything like that? i tried searching but wasnt able to find...... thanks and regards vivek.s (2 Replies)
Discussion started by: vivekshankar
2 Replies

9. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies

10. UNIX for Dummies Questions & Answers

How do you represent a field delimeter that is a space???

you know like if you want to work on a specified field in the password file. you would specify the field your interested in my telling the script that the fields are separated by a colon. now, my problem is that I want to specify a field that is not separated by a colon but by a space or tab... (1 Reply)
Discussion started by: TRUEST
1 Replies
Login or Register to Ask a Question