Remove unwanted question marks from with in a text file

Posted on 2016-08-26
Medium Priority
Last Modified: 2016-08-30
Hi All,
I have a text file which is thousands of lines long but for some reason I'm getting random question marks showing up on some lines which are not wanted.

Example lines in text file.

At the moment I just open the text file up in notepad and do a find and replace but I want to automate this in Powershell.
So I need a script which simply deletes all the question marks but leaves the rest of the line intact so from the above example to the below.



John Harris
Question by:phdit
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 41771816
Try with a single file copied in a test folder:

Dir |
Rename-Item -NewName { $_.Name -replace "?","" }

Open in new window

LVL 40

Accepted Solution

footech earned 2000 total points
ID: 41772012
I would try to investigate the source of the question marks.  For example:
- is it something that can be fixed by whatever generates the file?
- are they real question marks (certain programs will show a symbol that kind of looks like a question mark when there is a character that can not be displayed)?

To just remove the question marks though you can use the following.
(Get-Content yourfile.txt) -replace "\?" | Set-Content yourfile.txt

Open in new window


Author Comment

ID: 41776236
I will get blood out of a stone before I get a developer to look at the program that makes it.  So its up to me to fix it.

The above solution worked thanks.
LVL 40

Expert Comment

ID: 41776706
Glad to help.

Featured Post

WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question