How to grep for unicode � in a bash script
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
if grep -q "�" out.txt
then
echo "working"
else
cat out.txt
fi
Basically, if the file "out.txt" contains "�" anywhere in the file I would like it to echo "working" AND if the file "out.txt" does NOT contain "�" anywhere in the file then I would like it to cat out.txt
linux bash grep scripting
New contributor
add a comment |Â
up vote
2
down vote
favorite
if grep -q "�" out.txt
then
echo "working"
else
cat out.txt
fi
Basically, if the file "out.txt" contains "�" anywhere in the file I would like it to echo "working" AND if the file "out.txt" does NOT contain "�" anywhere in the file then I would like it to cat out.txt
linux bash grep scripting
New contributor
It looks correct, it should work (btw, I have no font for your unicode character to see, but none of them has any special meaning).grep
long understands unicode (which makes it much slower, so to search for ascii strings, aLANG=C grep
is a huge performance improvement).
â peterh
22 mins ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
if grep -q "�" out.txt
then
echo "working"
else
cat out.txt
fi
Basically, if the file "out.txt" contains "�" anywhere in the file I would like it to echo "working" AND if the file "out.txt" does NOT contain "�" anywhere in the file then I would like it to cat out.txt
linux bash grep scripting
New contributor
if grep -q "�" out.txt
then
echo "working"
else
cat out.txt
fi
Basically, if the file "out.txt" contains "�" anywhere in the file I would like it to echo "working" AND if the file "out.txt" does NOT contain "�" anywhere in the file then I would like it to cat out.txt
linux bash grep scripting
linux bash grep scripting
New contributor
New contributor
New contributor
asked 31 mins ago
Stuart Sloan
112
112
New contributor
New contributor
It looks correct, it should work (btw, I have no font for your unicode character to see, but none of them has any special meaning).grep
long understands unicode (which makes it much slower, so to search for ascii strings, aLANG=C grep
is a huge performance improvement).
â peterh
22 mins ago
add a comment |Â
It looks correct, it should work (btw, I have no font for your unicode character to see, but none of them has any special meaning).grep
long understands unicode (which makes it much slower, so to search for ascii strings, aLANG=C grep
is a huge performance improvement).
â peterh
22 mins ago
It looks correct, it should work (btw, I have no font for your unicode character to see, but none of them has any special meaning).
grep
long understands unicode (which makes it much slower, so to search for ascii strings, a LANG=C grep
is a huge performance improvement).â peterh
22 mins ago
It looks correct, it should work (btw, I have no font for your unicode character to see, but none of them has any special meaning).
grep
long understands unicode (which makes it much slower, so to search for ascii strings, a LANG=C grep
is a huge performance improvement).â peterh
22 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
try
grep -oP "[^x00-x7F]"
if .. then
statement as follows:
if grep -oP "[^x00-x7F]" file.txt; then
echo "grep found something"
else
echo "not found"
fi
Explanationð¡:
[^x00-x7F] is a regex to match a single non-ASCII character.
[[:ascii:]] - matches a single ASCII char
[^[:ascii:]] - matches a single non-ASCII char
in bash
LC_COLLATE=C grep -o '[^ -~]' file
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
try
grep -oP "[^x00-x7F]"
if .. then
statement as follows:
if grep -oP "[^x00-x7F]" file.txt; then
echo "grep found something"
else
echo "not found"
fi
Explanationð¡:
[^x00-x7F] is a regex to match a single non-ASCII character.
[[:ascii:]] - matches a single ASCII char
[^[:ascii:]] - matches a single non-ASCII char
in bash
LC_COLLATE=C grep -o '[^ -~]' file
add a comment |Â
up vote
5
down vote
try
grep -oP "[^x00-x7F]"
if .. then
statement as follows:
if grep -oP "[^x00-x7F]" file.txt; then
echo "grep found something"
else
echo "not found"
fi
Explanationð¡:
[^x00-x7F] is a regex to match a single non-ASCII character.
[[:ascii:]] - matches a single ASCII char
[^[:ascii:]] - matches a single non-ASCII char
in bash
LC_COLLATE=C grep -o '[^ -~]' file
add a comment |Â
up vote
5
down vote
up vote
5
down vote
try
grep -oP "[^x00-x7F]"
if .. then
statement as follows:
if grep -oP "[^x00-x7F]" file.txt; then
echo "grep found something"
else
echo "not found"
fi
Explanationð¡:
[^x00-x7F] is a regex to match a single non-ASCII character.
[[:ascii:]] - matches a single ASCII char
[^[:ascii:]] - matches a single non-ASCII char
in bash
LC_COLLATE=C grep -o '[^ -~]' file
try
grep -oP "[^x00-x7F]"
if .. then
statement as follows:
if grep -oP "[^x00-x7F]" file.txt; then
echo "grep found something"
else
echo "not found"
fi
Explanationð¡:
[^x00-x7F] is a regex to match a single non-ASCII character.
[[:ascii:]] - matches a single ASCII char
[^[:ascii:]] - matches a single non-ASCII char
in bash
LC_COLLATE=C grep -o '[^ -~]' file
edited 3 mins ago
answered 23 mins ago
Goro
8,38054282
8,38054282
add a comment |Â
add a comment |Â
Stuart Sloan is a new contributor. Be nice, and check out our Code of Conduct.
Stuart Sloan is a new contributor. Be nice, and check out our Code of Conduct.
Stuart Sloan is a new contributor. Be nice, and check out our Code of Conduct.
Stuart Sloan is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474709%2fhow-to-grep-for-unicode-in-a-bash-script%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
It looks correct, it should work (btw, I have no font for your unicode character to see, but none of them has any special meaning).
grep
long understands unicode (which makes it much slower, so to search for ascii strings, aLANG=C grep
is a huge performance improvement).â peterh
22 mins ago