Avatar of phdit
phdit

asked on 

Remove unwanted question marks from with in a text file

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
Powershell

Avatar of undefined
Last Comment
footech
Avatar of ltpitt
ltpitt

Try with a single file copied in a test folder:

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of phdit
phdit

ASKER

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.
Avatar of footech
footech
Flag of United States of America image

Glad to help.
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo