getting basename inside awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getting basename inside awk script
# 1  
Old 06-25-2009
getting basename inside awk script

hi if we have to use basename how can we do this in awk?
did the below but is not working..
Code:
 
psg  -t  "?"|  awk '{
                        command=($5 ~ /^[A-Z]/)? $9:$8
                       #  cmd_name=`basename $command` (gives error)
                        system("basename $command >> cmd_name") (isnot working )
                        }'

thanks
# 2  
Old 06-25-2009
why not using as the last field of awk?
# 3  
Old 06-25-2009
Something like this ?..
Code:
 
psg  -t  "?"|  awk '{
                        command=($5 ~ /^[A-Z]/)? $9:$8
                        exe="basename " cmd_name " >>" cmd_name
                        system(exe)                         
                       }'

# 4  
Old 06-26-2009
Quote:
Originally Posted by panyam
Something like this ?..
Code:
 
psg  -t  "?"|  awk '{
                        command=($5 ~ /^[A-Z]/)? $9:$8
                        exe="basename " cmd_name " >>" cmd_name
                        system(exe)                         
                       }'


Code:
 
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!!
# 5  
Old 06-26-2009
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:

Code:
exe="basename " command 
          system(exe)

# 6  
Old 06-26-2009
Quote:
Originally Posted by panyam
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:

Code:
exe="basename " command 
          system(exe)


I want to use the command variable like this than what i have to do??

Code:
 
psg  -t "?"| awk  '{
             command=($5 ~ /^[A-Z]/)? $9:$8
             exe="basename " command " >> command"
             system(exe)
             if (command == "tec")
             {
             printf(" second name %s \n",command)
             }
             }'

# 7  
Old 06-26-2009
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.
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