如何从文本中抓去 字符串
发表于 : 2009-03-02 8:53
本人ubuntu 有的时候 某些程序会出现”假死“的现象 于是 这些命令就很常用
ps -A | grep ...
kill -9 processID
于是 为了 方便(也不想用那个gnome-system-monitor) 所以就写了一个很简单的shell脚本 如下:
#! /bin/bash
echo "this script is to kill the process that seems dead"
echo "input the name of the process!(when you don't know the exact name you can do it like this [rhythmbox ==> rhy]"
read processname
ps -A | grep $processname > .proctmp
kill -9 `cut .proctmp -d " " -f 2`
echo " the choose process `cut .proctmp -d " " -f 8` has been killed"
echo " goodbye"
想必 大家看出来了 ps -A | grep $processname > .proctmp 和 cut .proctmp -d " " -f 8 我是想得到 进程的名字
比如 我首先打开stardict进程 然后 终端中执行以上脚本
就可以得到 很好的效果 the choose process stardict has been killed
但是 某些进程 最后却不能正确的显示名字 也就是 cut .proctmp -d " " -f 8 不能得到正确的结果
那从文本中截取字符串 应该用什么命令呢
ps -A | grep ...
kill -9 processID
于是 为了 方便(也不想用那个gnome-system-monitor) 所以就写了一个很简单的shell脚本 如下:
#! /bin/bash
echo "this script is to kill the process that seems dead"
echo "input the name of the process!(when you don't know the exact name you can do it like this [rhythmbox ==> rhy]"
read processname
ps -A | grep $processname > .proctmp
kill -9 `cut .proctmp -d " " -f 2`
echo " the choose process `cut .proctmp -d " " -f 8` has been killed"
echo " goodbye"
想必 大家看出来了 ps -A | grep $processname > .proctmp 和 cut .proctmp -d " " -f 8 我是想得到 进程的名字
比如 我首先打开stardict进程 然后 终端中执行以上脚本
就可以得到 很好的效果 the choose process stardict has been killed
但是 某些进程 最后却不能正确的显示名字 也就是 cut .proctmp -d " " -f 8 不能得到正确的结果
那从文本中截取字符串 应该用什么命令呢