Last active
October 7, 2018 10:58
-
-
Save photonxp/f7bd9f7c363ae85bbac117614b9534dc to your computer and use it in GitHub Desktop.
tag line editing, tag key editing
This file contains 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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment