extracting basename in awk or nawk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting basename in awk or nawk
# 1  
Old 01-29-2010
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 basename



Code:
{print basename infile, "line:", FNR, " blank field:", i}

Thank you for your help!!!

Last edited by rbatte1; 08-25-2016 at 01:12 PM.. Reason: Added ICODE tags, corrected spelling and emboldened commands
# 2  
Old 01-29-2010
Code:
awk -F/ '{print $NF}'

# 3  
Old 01-29-2010
Thank you!! Can I insert this in the original code?
Please see below. How should I do this? I would like to insert it in the bolded section. please help

Code:
 
for infile in /folder/file.1$.5$   
do

  nawk -v infile=$infile  ' {
      if(FILENAME=="pos.txt" )
      { 
           pos[FNR]=$1; len[FNR]=($2-$1)+1; vals++; next 
      }
      if(FILENAME==infile )
      {         
           for(i=1; i<=vals; i++)
           {
             testval=substr($0,pos[i], len[i])
             gsub(/ /, "", testval)
             if(length(testval)==0) {print infile, "line:", FNR, " blank field:", i}
           }  
           next         
      } 
  } '  pos.txt  $infile

done > report.txt

# 4  
Old 01-29-2010
Replace:
Code:
{print infile, "line:", FNR, " blank field:", i}

with:
Code:
{n=split(infile,a,"/");print a[n], "line:", FNR, " blank field:", i}

# 5  
Old 01-29-2010
Thank you!!!! Thank you alot!! It worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. UNIX for Dummies Questions & Answers

Help me to know about awk and nawk

Hi everyone, i am new to unix , so i want to know what is the use of awk and nawk. because in most of the place this cmds were used. so, if anyone provied the basic idea of this cmds, it will be much helpfull for me . . .. Thnks in Advance :) (9 Replies)
Discussion started by: natraj005
9 Replies

4. Shell Programming and Scripting

Extracting text with "nawk"

Hi - I have a simple file (x.xml): <tag1>text 1</tag1> <tag2>text 2</tag2> <tag3>text 3</tag3> <tag4>text 4</tag4> <tag5>text 5</tag5> I am trying to run a simple nawk script against it in order to get the text contained within the tags: nawk 'BEGIN{FS=""} /tag1/{tag1=$3}... (3 Replies)
Discussion started by: nfr816
3 Replies

5. Shell Programming and Scripting

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.. psg -t "?"| awk '{ command=($5 ~ /^/)? $9:$8 # cmd_name=`basename $command` (gives error) system("basename $command >>... (10 Replies)
Discussion started by: Anteus
10 Replies

6. Shell Programming and Scripting

Extracting email address using basename

Is it possible to use a variable as the delimiter using basename? I have a num variable that will be changing in the filename now. The files could looke like this my.email.address@mydomain.com.VL010600_474 my.email.address@mydomain.com.VL020600_474... (2 Replies)
Discussion started by: Drenhead
2 Replies

7. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

8. 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

9. Shell Programming and Scripting

Extracting part of the basename

Hi, I was wondering if there is an easy way to strip off the required basename. I have a script called apb0110021.sh and the contents of the script are typeset -u MScript=`basename $0 | cut -d. -f1` scriptname=sys.Audit.ksh parms="PROJECT1 dsAudit $MScript 1 BEGIN" $SCRIPTS/$scriptname... (3 Replies)
Discussion started by: madhunk
3 Replies
Login or Register to Ask a Question