0

I need to extract the file extension for the files in a directory, however the files are in the below format,

ab10001i.39400.8163.txt
ab10001i.39400.0433.txt
ab10001i.39400.24433.txt
ab10001i.39400.90631.TXT

I tried the below script , but didn't give me the expected results.. Any advise ? thank you!!

for file in "$SEARCH_DIR"/*; do
  clmFile=`basename "$file"`
  lastpart=``echo -n ${clmFile%.*} | tail -c4``
  echo "TEST THIS THIS " $lastpart
  if [ ${extension} == "TXT" ]; then
     echo "TXT FILE"
  elif [ ${extension} == "txt" ]; then
     echo "txt FILE"
  fi
done
busybear
  • 10,194
  • 1
  • 25
  • 42
Anto
  • 3
  • 6

1 Answers1

0

Found the solution..

lastpart=`echo -n ${clmFile%} | tail -c4

this will extract the output as below

txt
txt
txt
TXT

My Input files

ab10001i.39400.8163.txt
ab10001i.39400.0433.txt
ab10001i.39400.24433.txt
ab10001i.39400.90631.TXT

Is it a good script practice? Any other suggestions or recommendations?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Anto
  • 3
  • 6