1

Well, Before I decided to post this I have tried all the solutions provided here that are related to my issue. And I know it's a simple but this is my first time ever dealing with Bash .. so please bear with me a little

I have this Script

    FILES=*.html
for f in $FILES
do

  # extension="${f##*.}"
  filename="${f%.*}"
  echo "Converting $f to $filename.md"
  `pandoc $f -t markdown -o $filename.md`
  rm $f
done

This script was created to convert a directory full of Html files into markdown equivalents. It uses Pandoc to do the conversion.

The issue is this script will convert the file in the same exact folder only, and I want to convert all the files in subfolders like this:

Folder1/Folder2/folder3/index.html

So any ideas on how I could do this?

Sam Lee
  • 13
  • 2

1 Answers1

1

Use pretty much the same code but get the full path from find and watch out for whitespace

find ./path/to/start/from -iname "*.htm*" -exec bash -c 'fn=${1%.*}; sn=${fn##*/}; 
    echo "Converting $1 to $sn.md"; 
    pandoc "$1" -t markdown -o "$fn.md" && rm "$1"
' bash {} \;

the construct for find .....-exec

sh -c `some code here` sh {}

feeds the {} from bashback to bash -c as $1 and lets you play with it from there.

bu5hman
  • 4,756