Created
July 6, 2012 08:04
-
-
Save brunosan/3058846 to your computer and use it in GitHub Desktop.
A shell script that checks if the filename variable is present on YAML, and it adds it if not.
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 characters
| #!/bin/bash | |
| cd _posts | |
| for file in $(ls *.md) | |
| do | |
| if grep -Fq "filename: " $file | |
| then | |
| # code if found | |
| echo "File: $file already processed" | |
| else | |
| # code if not found | |
| echo "Adding the line on file: $file" | |
| awk -v n=2 -v s="filename: $file" 'NR == n {print s} {print}' $file > tmp.txt | |
| mv tmp.txt $file | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment