Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a text file that is processed by a third party. They told me the file is invalid because it contains a non-printable character. What's the best way to find the non-printable character as my normal text editors won't display it. I would prefer a windows, dos, or powershell based solution.
Option #1 - Show All Characters
You can download Notepad++ and open the file there. Then, go to the menu and select View->Show Symbol->Show All Characters. All characters will become visible, but you will have to scroll through the whole file to see which character needs to be removed.
Unfortunately, Notepad++ will automatically convert line endings according to your Edit->EOL Conversion selection, so it won't help if your non-printable characters are CR or LF.
Option #2 - TextFX Zap Non-printable Chars
Alternatively, you could install the TextFX plugin from SourceForge, and use TextFX->TextFX Characters->Zap all non-printable characters to #. This will replace some non-printable characters with a pound sign, but not CR or LF.
Option #3 - Remove BOM Encoding
Lastly, you could use Notepad++, and use Encoding->Convert to UTF8 without BOM. This will remove non-printable characters which occasionally causes issues with certain renderers (VSO).
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I made a program which takes numbers from the command line and adds them, the program is supposed to print an error if something else than a number is written, but when it reads > or < it creates text files with the results or rewrites on an already existing text file, if it doesn't exist it just stops without even running the code, is there a way to stop this from happening and read it just like another array?
Here is an example of the error
$ ./a +24 < 5
bash: 5: no such file or directory
That's not your program - that's the shell file I/O redirection. If you want your program to see the < or >, escape them appropriately:
./a +24 \<5
As ths others have said, it is not your program acting up, but the command line shell uses < and > as input/output redirection operators. You could escape them with backslashes.
But rather than forcing the users to escape each < and > (and possibly some other special characters like $ and the parentheses), you can quote the whole command line:
./a '1 < 24'
The whole command now is in argv[1]. You still have to parse it. As a bonus, there is no need to insert annoying spaces between the tokens anymore:
./a '1<24'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
for example, consider a file "abc.txt" has following content
{GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/name.inp"}
{GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/result.rst"}
{GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/abaqusresult.odb"}
So I want a script which will read this .txt file rearch for "*.rst" and replace with given name for example "badapple.rst"
or I will input "result.rst" search for it and replace it with "badapple.rst" keeping remaining all same and copy all other lines to new file
and I cannot change syntax of the text file it should exactly write
{GRAPHIC_FILE_1 = "E:/ge work/hyperview scripting/badapple.rst"}
To replace one string with another in a file, especially where you are changing the length of the string, you are going to find it easiest if you load the whole file into memory, perform the change there, then write it back out again.
set filename "abc.txt"
# Read in the file
set f [open $filename]
set content [read $f]
close $f
# Alter what is on $content here; !!READ BELOW!!
# Write out the file; assumes we've got the newlines in the content already
set f [open $filename "w"]
puts -nonewline $f $content
close $f
So what about that missing piece in the middle? Well, it depends on exactly what change you are trying to make. The details matter a lot here. However, if we are wanting to swap out result.rst for badapple.rst then that's pretty easy with string map (which replaces exact strings with other exact strings):
set content [string map {"result.rst" "badapple.rst"} $content]
Swapping every *.rst is a little trickier, as we need to define what * really matches here. I'm guessing that it doesn't include directory separators or double quotes! Given that, regsub -all is a more appropriate tool.
regsub -all {[^\\/""]+\.rst} $content "badapple.rst" content
Omitting the -all would make it just replace the first matching instance.
The regular expression is:
[^\\/""] — match any character that is not (^) a backslash, forward-slash or double-quote, with some things doubled for various reasons including quoting and readability
+ — one or more of the preceding piece (i.e., one or more non-bad characters)
\. — a full stop (requires a backslash because . is a RE metacharacter)
rst — three literal letter characters
If you're writing your own REs, always put it in {braces}.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'd like to edit multiple (~2000) txt files in Notepad ++. To be more specific: I'd like to narrow the entire text of into a column with newlines.
Like so:
into:
Of course it is not as simple, because the Text is dynamic and contains brackets for certain terms that will later help a search engine (Those will however not become unfunctional when separated with a newline which comes in very handy).
I found out that I can do so easily with the Line Operation "Split Line" in the "Edit" tab. Now I just need to do it with the rest of the files. I wonder if that can be automated? As it is not a macro it could be kind of tricky. Another thing I thought of was using a RegEx in the "Find in Files" option. Something like "find n characters with n spaces in between them" then "replace the exact same chars with the same chars but add a newline at the end".
Or "make a newline every 7 spaces".
Not sure if that is a viable approach, though.
Im curious about what you think about this. Any Suggestions?
In Find in Files, you may use
Find What: (?:^|\G)(\S*(?:\h+\S+){7})\h*
Replace With: $1\n
Do not forget to check the Regular expression radio button at the bottom.
Pattern details:
(?:^|\G) - either start of line or the end of the last successful match
(\S*(?:\h+\S+){7}) - Group 1 later referenced to with $1 backreference in the replacement pattern, capturing 0+ non-whitespace symbols, followed with exactly 7 sequences of 1+ horizontal whitespaces and 1+ non-whitespaces
\h* - zero or more horizontal whitespaces
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am using following code to create a new file cat15 using cat command in UNIX
# cat > cat15
this command adds a new file cat15 in root directory and whatever I type after this command is being stored into the file created. But I am not able to exit from this editor.
In other word, I am not getting Shell prompt symbol #
The cat command reads from STDIN if you don't specify a filename. It continues to do this until it receives an EOF or is killed. You can send an EOF and get your terminal back by typing <ctrl>+d.
What people generally do is to either use
touch filename
or
echo -n > filename
to create an empty file. As Charles correctly notes below, "echo -n" is not always a good idea (though you can usually count on it under "popular" Linux distros); I'd strongly suggest just using touch.
If you just want to create an empty file, regardless of whether one existed or not, you can just use ">" like this:
> cat15
It will clobber anything that already exists by that name.
I was recently editing a Unicode-encoded text file that also includes Thai characters (alongside "normal" characters). For some reason, after each sequence of Thai characters, a new line appeared.
After some mucking around with C, trying to remove all newline characters, I fired up vim to inspect the file. Apparently, after each Thai character sequence, there appears a "^M" string (without quotes).
Why is this happening, and what's that "^M"? I've found that I can fix the problem by removing the last three characters from the Thai string, but there surely must be a more elegant way to fix this ...
This has nothing to do with the fact that you have some Thai characters in the file. The ^M ('carrot M') is the representation of a Microsoft (DOS) carriage return. Dos2unix the file to get rid of these before editing it in vim.