Anteus
1
hi if we have to use basename how can we do this in awk?
did the below but is not working..
psg -t "?"| awk '{
command=($5 ~ /^[A-Z]/)? $9:$8
# cmd_name=`basename $command` (gives error)
system("basename $command >> cmd_name") (isnot working )
}'
thanks
clx
2
why not using as the last field of awk?
panyam
3
Something like this ?..
psg -t "?"| awk '{
command=($5 ~ /^[A-Z]/)? $9:$8
exe="basename " cmd_name " >>" cmd_name
system(exe)
}'
Anteus
4
psg -t "?"| awk '{
command=($5 ~ /^[A-Z]/)? $9:$8
exe="basename " command " >> command"
system(exe)
printf(" second name %s \n",command)
}'
its not printing the basename!!
panyam
5
Check in the current directory( where you executed the script) , a file with name "command" . The content of the file will be basename's output.
How ever if you want the system output to be seen on screen then make the following change in your script:
exe="basename " command
system(exe)
Anteus
6
I want to use the command variable like this than what i have to do??
psg -t "?"| awk '{
command=($5 ~ /^[A-Z]/)? $9:$8
exe="basename " command " >> command"
system(exe)
if (command == "tec")
{
printf(" second name %s \n",command)
}
}'
panyam
7
You can use ..the same working fine for me.
print "command" value and check wat ur getting ?..
I did n't understand the logic behind your script.
If you post input and output your expecting , then i hope you can get
more responces.
once again - why do you need to invoke an external command when you can do it all within awk natively?
Anteus
9
psg -t "?"| awk '{
command=($5 ~ /^[A-Z]/)? $9:$8
exe="basename " command " >> cmd_Name"
system(exe)
if (cmd_Name == "tec")
{
kill=1
}
if (kill ==1)
{
op=kill -9 " pid ";
system(op)
}
}'
I want get the name of the process and compare to check if it is "tec" process or not if it is ,then i would kill it.
---------- Post updated at 05:19 PM ---------- Previous update was at 05:13 PM ----------
how can we do it?
by doing natively do you mean to say using reg expression.?
one way......
myPathname="/a/b/c/d/myExec"
n=split(myPathname, a, "/")
print a[n]
Anteus
11
one more way..
psg -t "?"| awk '{
cname=($5 ~ /^[A-Z]/)? $9:$8
len=length(cname)
regex="/"
for(i=1;i<=len;i++)
{
where = index(cname,regex)
if(where)
{
cname= substr(cname,where+1)
}
}
printf("%s \n",cname)
}'