Skip to content

Instantly share code, notes, and snippets.

@brunosan
Created July 6, 2012 08:04
Show Gist options
  • Select an option

  • Save brunosan/3058846 to your computer and use it in GitHub Desktop.

Select an option

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.
#!/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