Skip to content

Instantly share code, notes, and snippets.

@hasn-prevas
Last active May 22, 2023 02:07
Show Gist options
  • Save hasn-prevas/01e2f7af5410bb7b8e2f4ec215d814d1 to your computer and use it in GitHub Desktop.
Save hasn-prevas/01e2f7af5410bb7b8e2f4ec215d814d1 to your computer and use it in GitHub Desktop.
Shell script to add UTF-8 BOM to any file
#!/bin/sh
BOM='\xEF\xBB\xBF'
if ! sed -n "1{/^$BOM/q1}" "$1"; then
echo "Already has BOM" >&2
exit 1
fi
sed -i "1s/^/$BOM/" "$1"
@ichengzi
Copy link

If on mac , sed is different from linux. brew install gnu-sed and replace the sed with gsed

#!/bin/sh

BOM='\xEF\xBB\xBF'
if ! gsed -n "1{/^$BOM/q1}" "$1"; then
    echo "Already has BOM" >&2
    exit 1
fi
gsed -i "1s/^/$BOM/" "$1"

@minhnguyenvan95
Copy link

add bom to all jsp file in project

find . -name "*.jsp" -exec ./add-bom.sh {} ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment