0

I have below code snippet working in bash:

for i in `ps -eaf | grep -i <pattern> | awk '{print $3}'`; do kill -9 $i; done

But I have a requirement to port this code to work in csh shell due to some legacy application is written using csh.

Sample output of "ps -eaf | grep -i | awk '{print $3}'"

5284

3543

14390

4811

4814

I am on RHEL 7.2 (tcsh-6.18.01-8.el7.x86_64, bash-4.2.46-19.el7.x86_64)

6
  • Hello, @dcds, you would like to get integer number frim where? Variable? Read it from a file? Commented Oct 9, 2018 at 10:55
  • Hi @Goro I will be getting process Ids by using some grep patterns. Commented Oct 9, 2018 at 11:24
  • would you please include example? this will be very helpful and our answer will be more accurate, after grep are these ids saved in a file or just variables Commented Oct 9, 2018 at 11:27
  • Hi @Goro I have updated the question. Commented Oct 9, 2018 at 11:59
  • Not in text file . I just want to run on terminal. Commented Oct 9, 2018 at 12:04

1 Answer 1

0
foreach i (`echo 1 2 3`)
  echo $i
end

Using your example:

foreach i (`ps -eaf | grep -i <pattern> | awk '{print $3}'`)
  kill -9 $i
end
2
  • I want to run this in single line in terminal. Commented Oct 9, 2018 at 12:12
  • the run it with xargs, as the other answer suggested: ps -eaf | grep -i <pattern> | awk '{print $3}' | xargs kill -9. foreach ... end cannot be on a single line in csh. Commented Oct 9, 2018 at 12:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.