Created
August 10, 2012 21:11
-
-
Save mprentice/3318015 to your computer and use it in GitHub Desktop.
Fix license text from xsl:comment to !--
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 | |
# Replace erroneous <xsl:comment> license tags with xml <!--> comments | |
bak="$HOME/tmp/xslbak" | |
mkdir -p "$bak" | |
find /usr/local/tusk/tusk-4_0_0 -name '*.xsl' -print0 | while IFS='' read -r -d '' fold ; do | |
lic=`awk '/<xsl:comment>/,/<\\/xsl:comment>/' "$fold" | grep 'licenses/ecl1\.php'` | |
if [ "" != "$lic" ] ; then | |
fdir="${fold%/*}" | |
fdir="${fdir#/usr/local/tusk/tusk-4_0_0/}" | |
fn="${fold##*/}" | |
fnew="$bak/$fdir/$fn" | |
mkdir -p "$bak/$fdir" | |
cp "$fold" "$fnew" | |
cat > "$fold" <<EOF | |
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
Copyright 2012 Tufts University | |
Licensed under the Educational Community License, Version 1.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.opensource.org/licenses/ecl1.php | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
--> | |
EOF | |
awk '/<xsl:stylesheet/,/<\/xsl:stylesheet>/' "$fnew" >> "$fold" | |
fi | |
done |
Change:
find /usr/local/tusk/tusk-4_0_0 -name '*.xsl' | while read -r f ; do
to
find /usr/local/tusk/tusk-4_0_0 -name '*.xsl' -print0 | while IFS='' read -r -d '' f ; do
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes:
/msg greybot !varcap
on freenode)basename
anddirname
should be replaced with parameter expansion expressions (/msg greybot basename
and/msg greybot dirname
, as appropriate)NEW
file every time you want to append a program's output to it is silly. Instead, you can open it once and reuse the file descriptor:exec 4>"$NEW"; one_command >&4; another_command >&4
#awk
channel, not the#bash
one, is appropriate for that.