skip to Main Content

Directory ~/a which contains subdirectories ~/a/b ~/a/c ~/a/d which themselves contain markdown files ~/a/b/1.md ~/a/c/2.md ~a/d/3.md and so on. How do I convert all the .md files in all of the subdirectories of ~/a to .txt files

I searched for possible answers and found pandoc but don’t know if it has the functionality and assume there is an preinstalled converter in debian which will be easier with a script.

2

Answers


  1. Chosen as BEST ANSWER

    When searching how to remove the file extension so it wouldn't save as md.txt after converting with the above script, I came across this:

    find . -name '*.md' -type f | while read NAME ; do mv "${NAME}" "${NAME%.md}" ; done

    Which converted all of the .md to plain text document 'UTF-8 Unicode text' which is fine for my needs.


  2. Like this:

    #!/bin/bash
    
    for file in ~/a/*.md do
        pandoc -f markdown -t plain --wrap=none "$file" -o "$file%.md}.txt" 
    done 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search