basename and dirname commands implemented in awk

basename implementation using awk. Get only filename

awk 'sub( /\/.*\//,"",$0 )' <<< '/usr/bin/ls'

dirname implementation using awk. Get only directory path

awk 'sub( /\/[a-z]*$/,"",$0 )' <<< '/usr/bin/ls'

Leave a comment