Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by soccerplayer
at 2024-11-25 08:19:48
Point:500 Replies:17 POST_ID:828825USER_ID:11733
Topic:
Unix Operating Systems;;Linux Programming
I would like to find all non-printable characters in a file. Questions:
1) Can somebody give me an example script?
2) If I want to replace all of them with a blank space or just nothing, how would I do it?
Thanks.
1) Can somebody give me an example script?
2) If I want to replace all of them with a blank space or just nothing, how would I do it?
Thanks.
Expert: duncanb7 replied at 2024-11-27 11:50:57
Thanks for your pt
Have a nice working day
Duncan
Have a nice working day
Duncan
Expert: duncanb7 replied at 2024-11-27 11:49:56
Just try those command I posted
such as tr, sed, vi
or send us your issue file if it is not too big
Otherwise, I have no more idea or room for your issue
and I will quit this thread
have a nice day
Duncan
such as tr, sed, vi
or send us your issue file if it is not too big
Otherwise, I have no more idea or room for your issue
and I will quit this thread
have a nice day
Duncan
Author: soccerplayer replied at 2024-11-27 11:46:07
I found the solution through browsing. Thank for you very much.
Author: soccerplayer replied at 2024-11-27 11:36:36
I see ^M character as well and it certainly is not printable. <92> is a non-printable character for apostrophe. How do I search for it is my issue.
Expert: duncanb7 replied at 2024-11-27 11:24:33
if you actually see the <92> that is printable char
so why not just
:s/<92>/x/ to replace to x or delete it
DUncan
so why not just
:s/<92>/x/ to replace to x or delete it
DUncan
Author: soccerplayer replied at 2024-11-27 11:20:27
I tried, after vi-ing the file:
:s/x92/ /
It tells me:
Pattern not found: x92
whereas I clearly see the <92> in the file.
:s/x92/ /
It tells me:
Pattern not found: x92
whereas I clearly see the <92> in the file.
Expert: duncanb7 replied at 2024-11-27 10:34:38
Dear soccerplayer,
On linux shell , you can dos2unix command covert the fle from dos to unix format
On vi editor, you can convert the file from dos to unix format by command
:set fileformat=unix
If those don't help at all,
-try it in VI to detele ^M
:s/^M/x / ###that will convert ^M to x or other char you like. you can type ctrl-v to
get "^"
-for<92>, <93>, I believe that is extended ascill code in Hex
http://www.ascii-code.com/, and that are ’ and “ respectively
-try it in VI to replace or delete
:s/x92/x/ ###-replace hex92 to x
:s/x93/x/ ###-repace hex93 to x
If you send us the file, that will be easier for us to help
Duncan
On linux shell , you can dos2unix command covert the fle from dos to unix format
On vi editor, you can convert the file from dos to unix format by command
:set fileformat=unix
If those don't help at all,
-try it in VI to detele ^M
:s/^M/x / ###that will convert ^M to x or other char you like. you can type ctrl-v to
get "^"
-for<92>, <93>, I believe that is extended ascill code in Hex
http://www.ascii-code.com/, and that are ’ and “ respectively
-try it in VI to replace or delete
:s/x92/x/ ###-replace hex92 to x
:s/x93/x/ ###-repace hex93 to x
If you send us the file, that will be easier for us to help
Duncan
Author: soccerplayer replied at 2024-11-27 09:00:46
Can you tell me if I have a non-printable character such as <92>, <93> or ^M., how do I search for it using vi? That's all I need to know.
Expert: duncanb7 replied at 2024-11-26 21:51:38
Could you send your issue file to us so that we can solve it ?
After sending your file, please download the file you send to us and
test it at your side again to cehck whether it is issue file you're talking about
that action is helping we will receive the correct issue file you sent for cross-check
If not repeat your issue at our side , it might be related to unix and dos format file issue
Duncan
After sending your file, please download the file you send to us and
test it at your side again to cehck whether it is issue file you're talking about
that action is helping we will receive the correct issue file you sent for cross-check
If not repeat your issue at our side , it might be related to unix and dos format file issue
Duncan
Author: soccerplayer replied at 2024-11-26 21:38:03
Two questions:
1) How do I search after getting into vi? I tried doing:
/<92>
It didn't work.
2) How do I find out what the values of these characters are?
Thanks.
1) How do I search after getting into vi? I tried doing:
/<92>
It didn't work.
2) How do I find out what the values of these characters are?
Thanks.
Expert: duncanb7 replied at 2024-11-25 14:18:27
you can try 92 as 33 in my example if it is non-printable.
And please review those post I wrote in this thread.
Duncan
And please review those post I wrote in this thread.
Duncan
Author: soccerplayer replied at 2024-11-25 13:59:32
<92> is not a string. It is a non-printable character in my file just like ^M. My biggest problem is, I have them in my file but how do I search for them?
Accepted Solution
Expert: duncanb7 replied at 2024-11-25 11:41:53
500 points EXCELLENT
To relace <90> string into "newstr" on linux
sed -i 's/<90>/newstr/g' yourfile.txt
To find and replace non-printable char with other char like 'x' or anything you wnat
try it on linux .
tr ' 33' 'x' < yourfile.txt >output.txt
or
sed 's/o33/x/g' yourfile.txt >output.txt;
or in hex
sed 's/x1b/x/g' yourfile.txt >output.txt;
or with output to the same file
sed -i 's/o33/x/g' yourfile.txt
Hope it help
Duncan
sed -i 's/<90>/newstr/g' yourfile.txt
To find and replace non-printable char with other char like 'x' or anything you wnat
try it on linux .
tr ' 33' 'x' < yourfile.txt >output.txt
or
sed 's/o33/x/g' yourfile.txt >output.txt;
or in hex
sed 's/x1b/x/g' yourfile.txt >output.txt;
or with output to the same file
sed -i 's/o33/x/g' yourfile.txt
Hope it help
Duncan
Author: soccerplayer replied at 2024-11-25 11:36:52
When I did a vi file_name, I found some characters such as <92> and <93>. I am trying to find out how I can search for them and replace them if needed.
Expert: duncanb7 replied at 2024-11-25 11:31:34
To remove ^M, you can do this as follows , what your mean <90> ? you mean 90 in DEC
at http://www.asciitable.com/
Duncan
How we can solve it then?
To Solve ^M at last in each line we can do following things:
1-Linux Command shell
dos2unix file-name new-file-name
(dos2unix is a Linux utility tool which can convert windows oriented file to Linux compatible, so it will remove ^M automatically from the end of each line
2-By setting vim configuration file i.e. .vimrc
Open .vimrc which will be at your home location i.e. /home/aliencoders/.vimrc
And save this line
set ffs=unix,dos
3-By editing the file manually . Open test.txt in vim editor and use the following command to substitute in command mode i.e after pressing esc button.
:1,$s/^M//g or :%s/^M//g (Actually ctrl+v and ctrl+ M will show you ^M)
4-By using strings command in Linux. This command can omit all non-printable characters from the file.
strings file-name > new-file-name
Now, this new-file-name will not contain those non-printable characters.
Taken from www.aliencoders.com/content/how-remove-m-and-other-non-printable-characters-file-linux?page=1
at http://www.asciitable.com/
Duncan
How we can solve it then?
To Solve ^M at last in each line we can do following things:
1-Linux Command shell
dos2unix file-name new-file-name
(dos2unix is a Linux utility tool which can convert windows oriented file to Linux compatible, so it will remove ^M automatically from the end of each line
2-By setting vim configuration file i.e. .vimrc
Open .vimrc which will be at your home location i.e. /home/aliencoders/.vimrc
And save this line
set ffs=unix,dos
3-By editing the file manually . Open test.txt in vim editor and use the following command to substitute in command mode i.e after pressing esc button.
:1,$s/^M//g or :%s/^M//g (Actually ctrl+v and ctrl+ M will show you ^M)
4-By using strings command in Linux. This command can omit all non-printable characters from the file.
strings file-name > new-file-name
Now, this new-file-name will not contain those non-printable characters.
Taken from www.aliencoders.com/content/how-remove-m-and-other-non-printable-characters-file-linux?page=1
Author: soccerplayer replied at 2024-11-25 11:19:24
duncanb7, your link allows me to remove characters. What if I want to replace them? For example, I came across characters such as ^M and <92> or <93>. Questions:
1) What are the actual characters for <92> and <93> in Unix?
2) How do I replace them with a space or some printable character?
1) What are the actual characters for <92> and <93> in Unix?
2) How do I replace them with a space or some printable character?
Expert: duncanb7 replied at 2024-11-25 08:45:38
Please try this tr command,
tr -cd '11121540-176' yourfile.txt(with non-printable char) outputfile.txt(take out all non-printable char)
Please take a look at this article that might help
http://alvinalexander.com/blog/post/linux-unix/how-remove-non-printable-ascii-characters-file-unix
http://www.asciitable.com/
Hope understand your question completely, if not please point it out
Duncan
tr -cd '11121540-176' yourfile.txt(with non-printable char) outputfile.txt(take out all non-printable char)
Please take a look at this article that might help
http://alvinalexander.com/blog/post/linux-unix/how-remove-non-printable-ascii-characters-file-unix
http://www.asciitable.com/
Hope understand your question completely, if not please point it out
Duncan