• Tags
  • Documentation
  • Order
  • Register
  • Login
Duet3D Logo Duet3D
  • Tags
  • Documentation
  • Order
  • Register
  • Login

Bash script, all files in directory - formatted text dump

Scheduled Pinned Locked Moved
General Discussion
1
3
313
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • undefined
    Kolbi
    last edited by Kolbi 8 Mar 2020, 08:43 3 Aug 2020, 06:19

    I've made a very simple bash script that outputs the contents of each file within the designated directory to terminal. This can be useful for troubleshooting, code verification, sharing, ...
    To put output to a file, follow this example: me:~ me$ ./lister.sh > dump/sys.md

    cd /PATH-TO-SDCARD-FILES/sys/
    for i in *
    do
    echo "**$i - v$(date +%D)**"
    echo "\`\`\`g-code"
    more "$i"
    echo
    echo "\`\`\`"
    done

    You can also copy the text contents, paste in the forum and have it nicely displayed in easy to read code blocks. An example output from my printer can be found here: https://github.com/rkolbi/RRF-machine-config-files/blob/master/Prusa MK3s/ALLFiles.md

    Cheers,
    Kolbi

    1 Reply Last reply Reply Quote 2
    • undefined
      Kolbi
      last edited by Kolbi 8 Jul 2020, 23:23 7 Aug 2020, 21:10

      Updated the script a bit, kinda messy but it works well 😉
      On my Mac, I place it in ~/bin/ as 'lister'

      Use from cli:
      me:~ me$ lister /Users/me/rfm/backup-dir

      Where '/Users/me/rfm/backup-dir' is the location that my target files reside.
      In this script, I set the results to be placed on my Desktop as:
      /Users/me/Desktop/dump.md
      /Users/me/Desktop/dump-list.md (includes the complete list of directorys and file names before presenting the contents)

      You can see a working example here on the last page - or here: dump-list.pdf where I just exported it to pdf.

      #!/bin/bash
      strip=$1
      echo "### file dump - v$(date +%D)" > /Users/me/Desktop/dump-list.md
      echo "### Directory / File list follow:" >> /Users/me/Desktop/dump-list.md
      echo "" > /Users/me/Desktop/dump.md
      print_file_recursively() {
      FILE_NAME="$(basename "${entry}")"
      echo "$FILE_NAME " >> /Users/me/Desktop/dump-list.md
      echo "##### ${entry#"$strip"}" >> /Users/me/Desktop/dump.md
      echo "\`\`\`g-code" >> /Users/me/Desktop/dump.md
      more "$entry" >> /Users/me/Desktop/dump.md
      echo >> /Users/me/Desktop/dump.md
      echo "\`\`\`" >> /Users/me/Desktop/dump.md
      }
      # loop and print all file and folder recursively,
      print_recursively() {
      local indent="${2:-0}"
      echo "**${1#"$strip"}** " >> /Users/me/Desktop/dump-list.md
      echo "#### ${1#"$strip"}" >> /Users/me/Desktop/dump.md
      for entry in "$1"/*; do
      [[ -f "$entry" ]] && print_file_recursively
      done
      for entry in "$1"/*; do
      [[ -d "$entry" ]] && print_recursively "$entry"
      done
      }
      # Check folder
      PATH_FOLDER=""
      if [ -d "$1" ]; then
      PATH_FOLDER=$1;
      fi
      print_recursively $PATH_FOLDER
      echo "" >> /Users/me/Desktop/dump-list.md
      echo "" >> /Users/me/Desktop/dump-list.md
      echo "### File contents follow:" >> /Users/me/Desktop/dump-list.md
      echo "****" >> /Users/me/Desktop/dump-list.md
      echo "" >> /Users/me/Desktop/dump-list.md
      more /Users/me/Desktop/dump.md >> /Users/me/Desktop/dump-list.md
      echo "Done."
      1 Reply Last reply Reply Quote 0
      • undefined
        Kolbi
        last edited by 7 Aug 2020, 23:40

        Forgot to mention, if you are going to use the output for use in a code block within this forum, you'll need to do either of two things...
        Replace

        echo "\`\`\`g-code" >> /Users/me/Desktop/dump.md
        

        with

        echo "\`\`\`" >> /Users/me/Desktop/dump.md
        

        -or-
        Open the output file in a text editor, and do a search/replace; search for ```g-code and replace with ```

        1 Reply Last reply Reply Quote 0
        1 out of 3
        • First post
          1/3
          Last post
        Unless otherwise noted, all forum content is licensed under CC-BY-SA