Solved

Remove unwanted question marks from with in a text file

Posted on 2016-08-26
4
79 Views
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.
?07,2096690,A-100?,07_2096690,07-00000177\07-00000001.PDF
07,2096124,J-027,07_2096124,07-00000177\07-00000003.PDF
07,2096633,K-006,07_2096633,07-00000177\07-00000005.PDF
07,2096740,P-029,07_209?6740,07-00000177\07-00000?008.PDF

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.

07,2096690,A-100,07_2096690,07-00000177\07-00000001.PDF
07,2096124,J-027,07_2096124,07-00000177\07-00000003.PDF
07,2096633,K-006,07_2096633,07-00000177\07-00000005.PDF
07,2096740,P-029,07_2096740,07-00000177\07-00000008.PDF

Regards

John Harris
0
Comment
Question by:phdit
[X]
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
4 Comments
 
LVL 1

Expert Comment

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

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

Open in new window

0
 
LVL 40

Accepted Solution

by:
footech earned 500 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

0
 

Author Comment

by:phdit
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.
0
 
LVL 40

Expert Comment

by:footech
ID: 41776706
Glad to help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

707 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