Last active
November 24, 2021 11:52
-
-
Save arthurattwell/55d168c6b584e901b3f9eaa80ca97063 to your computer and use it in GitHub Desktop.
Revisions
-
arthurattwell revised this gist
Dec 8, 2018 . 1 changed file with 5 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,16 @@ #!/bin/bash # That tells Linux to use a Bourne shell interpreter. # Run this script from the current directory. (Required on OSX.) cd -- "$(dirname "$0")" # Don't echo these commands. set +v # Get the filename from the user. echo "Enter the file name to split: " read filename echo 'Splitting' $filename ' ...' # Replace the first of each set of YAML frontmatter # with a string delimiter we can replace later. @@ -21,7 +19,7 @@ echo 'Splitting ' $filename ' ...' perl -i -0pe 's/(^---$)(.+?)(^---$)/---thisisnotthreehyphens$2---/gms' $filename # Get the number of splits we're going to do. frontmatter=$(grep -c "^\-\-\-thisisnotthreehyphens$" "$filename") echo 'Found' $frontmatter 'markdown docs.' # Set the number of times we'll repeat the csplit. @@ -49,4 +47,4 @@ for file in xx* done # All done! echo 'Done!' -
arthurattwell revised this gist
Dec 8, 2018 . 1 changed file with 16 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,10 @@ #!/bin/bash # That tells Linux to use a Bourne shell interpreter. # On OSX, run this script from the current directory. if [[ "$OSTYPE" == "darwin"* ]]; then d -- "$(dirname "$0")" fi # Don't echo these commands. set +v @@ -18,10 +20,16 @@ echo 'Splitting ' $filename ' ...' # one line at a time. perl -i -0pe 's/(^---$)(.+?)(^---$)/---thisisnotthreehyphens$2---/gms' $filename # Get the number of splits we're going to do. frontmatter=$(grep -c "^\-\-\-thisisnotthreehyphens$" t.md) echo 'Found' $frontmatter 'markdown docs.' # Set the number of times we'll repeat the csplit. # This should be one less than the number of frontmatters. csplitRepeats=$(($frontmatter-1)) # Split the file at the delimiter we just created. csplit -ks $filename '/---thisisnotthreehyphens/' {$csplitRepeats} # In the original file and the files we just created, # remove the string we put there as a delimiter. @@ -35,7 +43,9 @@ rm xx00 for file in xx* do perl -i -pe 's/---thisisnotthreehyphens/---/' $file newFilename=${file/xx/}.md mv "$file" "$newFilename" echo 'Created' $newFilename done # All done! -
arthurattwell revised this gist
Dec 8, 2018 . 1 changed file with 16 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,33 +1,41 @@ #!/bin/bash # That tells Linux to use a Bourne shell interpreter. # Run this script from the current directory. (Required on OSX.) d -- "$(dirname "$0")" # Don't echo these commands. set +v # Get the filename from the user. echo "Enter the file name to split: " read filename echo 'Splitting ' $filename ' ...' # Replace the first of each set of YAML frontmatter # with a string delimiter we can replace later. # This is necessary because csplit can only search # one line at a time. perl -i -0pe 's/(^---$)(.+?)(^---$)/---thisisnotthreehyphens$2---/gms' $filename # Split the file at the delimiter we just created. # OSX's csplit can't use {*}, so we use a real number 10000. # This means, technically, this will only split up to 10000 files. csplit -ks $filename '/---thisisnotthreehyphens/' {10000} # In the original file and the files we just created, # remove the string we put there as a delimiter. perl -i -pe 's/---thisisnotthreehyphens/---/' $filename # Remove the first, blank file. (We assume there is # nothing before our first '---' that we want to keep.) rm xx00 # Put back the '---' in the files we created, and rename them. for file in xx* do perl -i -pe 's/---thisisnotthreehyphens/---/' $file mv "$file" "${file/xx/}.md" done # All done! -
arthurattwell created this gist
Nov 16, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ #!/bin/bash # That tells Linux to use a Bourne shell interpreter. # Don't echo these commands: set +v # Get the filename from the user echo "Enter the file name to split: " read filename # Replace the first of each set of YAML frontmatter # with a string delimiter we can replace later. # This is necessary because csplit can only search # one line at a time. perl -i -0pe 's/(^---$)(.+?)(^---$)/---thisisnotthreehyphens$2---/gms' $filename # Split the file at the delimiter we just created csplit -ks $filename '/---thisisnotthreehyphens/' {*} # In the original file and the files we just created, perl -i -pe 's/---thisisnotthreehyphens/---/' $filename # Remove the first, blank file (we assume there is # nothing before our first --- that we want to keep) rm xx00 # Put back the --- in the files we created, and rename them for file in xx* do perl -i -pe 's/---thisisnotthreehyphens/---/' $file rename -f 's/xx(\d+)/$1.md/' $file done # All done! echo 'Done!'