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
Solved

Remove unwanted question marks from with in a text file

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article will help you understand what HashTables are and how to use them in PowerShell.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

792 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