tag line editing, tag key editing
#!/bin/bash
# Tag line editing
# Change the line
# from
# vocabulary grammar
# to
# tag:: vocabulary grammar
# Change by a given tag value such as "vocabulary" or "grammar"
# Omit the tag line if they already have the key word of "tag"
# Use the -r [extended regex pattern]
# Backup your data first if they're important
data_dir=/path/to/data
tagvalue="vocabulary"
tagline_filter="/^tag/!"
tagkey="tag:: "
filtered_operation="s/^(.*$tagvalue([[:space:]]|$))/$tagkey\1/"
sed_directive="$tagline_filter $filtered_operation"
# echo "$sed_directive"
find_cmd="find $data_dir -maxdepth 1 -type f"
for fpath in `$find_cmd`
do
echo $fpath
# -r for extended regex
sed -r "$sed_directive" -i $fpath
done