getting basename inside awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getting basename inside awk script
# 8  
Old 06-26-2009
once again - why do you need to invoke an external command when you can do it all within awk natively?
# 9  
Old 06-26-2009
Quote:
Originally Posted by panyam
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.

Code:
 
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 ----------

Quote:
Originally Posted by vgersh99
once again - why do you need to invoke an external command when you can do it all within awk natively?


how can we do it?
by doing natively do you mean to say using reg expression.?
# 10  
Old 06-26-2009
one way......
Code:
myPathname="/a/b/c/d/myExec"
n=split(myPathname, a, "/")
print a[n]

# 11  
Old 07-02-2009
one more way..

Code:
 
              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)
          }'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make change to variable value inside of awk script

Hello, I have text data that looks like this, Mrv16a3102061815532D 6 6 0 0 0 0 999 V2000 -0.4018 1.9634 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -1.1163 1.5509 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -1.1163 0.7259 ... (9 Replies)
Discussion started by: LMHmedchem
9 Replies

2. Shell Programming and Scripting

awk inside shell and script aborting

Hi I have a requirement where i need to convert the xml in various lines into a single line and then split the file so that the file contains only 1000 records each. searching this forum, i found a command which converts the xml in various line into a single line, but i have trouble using that... (3 Replies)
Discussion started by: maximus_jack
3 Replies

3. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

4. Shell Programming and Scripting

awk & basename puzzler - advise sought

Hi I have been able generate a file ($ELOG) that can have multiple lines within it. The first column represents the full path source file and the other is the full path target ... the file names are the same but the target directory paths are slightly different. <source_dir1>/file1 ... (4 Replies)
Discussion started by: davidra
4 Replies

5. UNIX for Dummies Questions & Answers

awk and basename

im trying to extract the basename of a process running on a host processx is running at host1 as /applications/myapps/bin/processx i wanted to check if its running, then extract the basename only using: $ ssh host1 "ps aux | grep -v 'grep' | grep 'processx'" | awk '{ print basename $11}' ... (10 Replies)
Discussion started by: kaboink
10 Replies

6. Programming

Executing a awk command inside perl script --

Hello experts I want to execute a awk command, which reads from txt files and sums the numbers from the first column for those listed only inside a <init> block -- The awk command is like awk '/<\/?init>/{x = !x}x{a++}x && a > 2{sum+=$1}END{printf"%E" "\n", sum} So, I want to execute... (2 Replies)
Discussion started by: Alkass
2 Replies

7. Shell Programming and Scripting

Write Awk output to a file , inside script.

Hi, Can anyone please help me with this issue. I have a Awk command which take file as input, and provides the output having multiple lines, its working in command mode, but not if i plug it in script. #!/bin/ksh infile=a.txt outfile=b.txt awk ' BEGIN{ FS=OFS="|";ORS = "\n";... (1 Reply)
Discussion started by: sp999
1 Replies

8. UNIX for Dummies Questions & Answers

using awk inside bash script?

Hello, I'm trying to write a bash script that will query the current system time (OS X 10.6.6) and then convert the output from HH:MM:SS into time in seconds. The output of the system time command (systemsetup -gettime) is returned as: Time: HH:MM:SS so I wanted to use awk -F: to grab... (5 Replies)
Discussion started by: xaiu
5 Replies

9. Shell Programming and Scripting

extracting basename in awk or nawk

I am having a hard time extracting the file name from the above code. Instead of printing /folder/file.1$.5$, I would like it to print the file name file.1$.5$. I have tried using basename but it looks like NAWK or AWK does not recognise basename. Each time I type it in, it prints out the word... (4 Replies)
Discussion started by: asemota
4 Replies

10. Shell Programming and Scripting

Using find command with awk or basename

Hi, I am using the following command to extract any log files that are older than 3 days using the following command. find DIR/LOGDIR -type f -mtime +3 |grep LOG > log_list.out The results are DIR/LOGDIR/1.LOG DIR/LOGDIR/2.LOG DIR/LOGDIR/3.LOG DIR/LOGDIR/4.LOG How do inculde (basename... (4 Replies)
Discussion started by: sam_78_nyc
4 Replies
Login or Register to Ask a Question