Solved

Remove unwanted question marks from with in a text file

Posted on 2016-08-26
4
45 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
  • 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 39

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 39

Expert Comment

by:footech
ID: 41776706
Glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
A brief introduction to what I consider to be the best editor for PowerShell.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now