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)

  • Hello, @dcds, you would like to get integer number frim where? Variable? Read it from a file? – user88036 Oct 9 '18 at 10:55
  • Hi @Goro I will be getting process Ids by using some grep patterns. – dcds Oct 9 '18 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 – user88036 Oct 9 '18 at 11:27
  • Hi @Goro I have updated the question. – dcds Oct 9 '18 at 11:59
  • Not in text file . I just want to run on terminal. – dcds Oct 9 '18 at 12:04
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
  • I want to run this in single line in terminal. – dcds Oct 9 '18 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. – qubert Oct 9 '18 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.