Solved

Remove unwanted question marks from with in a text file

Posted on 2016-08-26
4
42 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
A procedure for exporting installed hotfix details of remote computers using powershell
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

19 Experts available now in Live!

Get 1:1 Help Now