DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: instr() like function with awk

  1. #1
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    Hi

    Does anyone know if awk as any function which works as instr() sql function?

    for example

    echo kk.FmB | awk '{print substr($0, 1+index($0, "."),3) }'

    this returns FmB

    but if the file name has more than 1 . then I would be screwed!


    cheers

  2. #2
    Join Date
    Sep 2001
    Location
    NJ, USA
    Posts
    1,287
    try to use FS -> field separator and NF -> # of fields

    echo abc.dfg.sss | awk -F. '{print $(NF), NF, FS}'
    will print
    sss 3 .

    echo abc.dfg.sss | awk -F. '{print $(NF-1), NF, FS}'
    will print
    dfg 3 .


    echo abc.dfg.sss | awk -F. '{print $(NF)}'
    will print
    sss

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width