Skip to content

Instantly share code, notes, and snippets.

@debdutgoswami
Last active December 19, 2020 10:53
Show Gist options
  • Save debdutgoswami/ba70c52e675285667930afa59d65fd30 to your computer and use it in GitHub Desktop.
Save debdutgoswami/ba70c52e675285667930afa59d65fd30 to your computer and use it in GitHub Desktop.
This is simple shell script written to help create PDF from all of the java codes in a directory. All you need to do is pass in your directory path and target name and that's it.
#!/bin/bash
## Usage:
## `./create-assignment.sh <directory> <target> <extension>`
## Example:
## `./create-assignment.sh Assignment-1/Day-1 23_Hello_world_A7 java`
directory=$1
target=$2
extension=$3
count=1
for FILE in $(ls "$directory" | grep "\.${extension}$"); do
# grouping multiple commands in a single block
{
printf "Code %s:\n\n" "${count}"
cat "${directory}/${FILE}"
printf "\n\n\n**************************************************************\n\n\n"
} >>"${target}"
count=$((count + 1))
done
# convert to pdf using libreoffice
libreoffice --headless --convert-to pdf "${target}"
rm "${target}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment