79410178

Date: 2025-02-03 22:42:53
Score: 1
Natty:
Report link

Why not keep it simple?

#!/bin/zsh
for f in /test_data/*; do
    str=$f
    root=${str%/*}  #Remove everything from the right to the first / from the right
    name=${str##*/} #Remove everything from the left to the last / from the left
    echo "Root = " $root
    filename=$(echo $name | awk -F . '{print $1}')
    extension=$(echo $name | awk -F . '{ print $2 }')
    echo "Name = " $filename
    echo "Extension = " $extension
 done;

If there is no extension, then the variable will be empty

Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Why not
  • Low reputation (0.5):
Posted by: Todd Vanyo