Skip to content

Instantly share code, notes, and snippets.

@MechCoder
Created August 21, 2015 08:15
Show Gist options
  • Save MechCoder/fdc77f62050f2f698484 to your computer and use it in GitHub Desktop.
Save MechCoder/fdc77f62050f2f698484 to your computer and use it in GitHub Desktop.
Replace since by Since
echo "Enter file name"
read file_name
output=$(grep -n 'since' $file_name)
echo "$output" > tmp.txt
while read name
do
IFS=': ' read -ra line_and_since <<< "$name"
line_no="${line_and_since[0]}"
version_no="${line_and_since[-1]}"
next_line=$((line_no + 1))
echo "${name}"
sed -i "${line_no}s/ @since [0-9].[0-9].[0-9]/\//" "$file_name"
sed -i "${next_line}s/*\//@Since(\"${version_no}\")/" "$file_name"
sed -i "${next_line}s/ @Since/@Since/" "$file_name"
done < tmp.txt
# This is to remove empty docstrings, however it fails in badly formatted docs.
# x=0
# output=$(grep -n 'Since' $file_name)
# echo "$output" > tmp.txt
# while read name
# do
# IFS=': ' read -ra line_and_since <<< "$name"
# line_no="${line_and_since[0]}"
# version_no="${line_and_since[-1]}"
# prev_line=$((line_no - 2 - x))
# line="`sed -n "${prev_line}p" "$file_name"`"
# if [[ `echo $line | grep '/\/*/*' ` ]]
# then
# # Remove empty docstrings like
# # /**
# # */
# if [[ "${#line}" -eq 3 ]]
# then
# x=$((x - 2))
# sed -i "${prev_line}d" "$file_name"
# sed -i "${prev_line}d" "$file_name"
# fi
# fi
# done < tmp.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment