Skip to content

Instantly share code, notes, and snippets.

@homleen
Created June 6, 2013 11:40
Show Gist options
  • Save homleen/5720923 to your computer and use it in GitHub Desktop.
Save homleen/5720923 to your computer and use it in GitHub Desktop.
批量替换文件第一行
for file in *.xml; do
is_head_xml=$(head -n 1 $file | grep -e '<?xml')
if [ -z "$is_head_xml" ]; then
echo $file
else
sed '1s/^.*$/<?xml version="1.0" encoding="utf-8"?>/' $file > ./output/$file
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment