Remove white spaces and replace "-" with 0 - JREPL?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Remove white spaces and replace "-" with 0 - JREPL?

#1 Post by SIMMS7400 » 29 Oct 2017 08:42

Hi Folks -

I'm looking for an efficient way to remove leading and trailing white spaces and replace ", - " with ",0" in column 4 of my .csv.

Here is a portion of my data file:

Code: Select all

US_4672,PFP-A1045900,12/1/2017, 0.75 
US_4672,PFP-A1045900,3/1/2018, 0.75
US_4672,PFP-A1045900,6/1/2018, 0.75
US_4672,PFP-A1045900,9/1/2018, 0.75
US_4672,PFP-A1045900,12/1/2018, 0.75
US_4672,PFP-A1045900,3/1/2019, 0.75
US_4672,PFP-A1045900,6/1/2019, 0.75
US_4672,PFP-A1045900,9/1/2019, 0.75
US_4672,PFP-A1045900,12/1/2019, 0.75
US_4672,PFP-A1045900,3/1/2020, 0.75
US_4641,PFP-A1045900,12/1/2017, 0.50
US_4641,PFP-A1045900,3/1/2018, 0.50
US_4641,PFP-A1045900,6/1/2018, 0.50
US_4641,PFP-A1045900,9/1/2018, 0.50
US_4641,PFP-A1045900,12/1/2018, 0.50
US_4641,PFP-A1045900,3/1/2019, 0.50
US_4641,PFP-A1045900,6/1/2019, 0.50
US_4641,PFP-A1045900,9/1/2019, 0.50
US_4641,PFP-A1045900,12/1/2019, 0.50
US_4641,PFP-A1045900,3/1/2020, 0.50
US_367,PFP-A1049600,12/1/2017, 1.00
US_367,PFP-A1049600,3/1/2018, 0.50
US_367,PFP-A1049600,6/1/2018, -   
US_367,PFP-A1049600,9/1/2018, -   
US_367,PFP-A1049600,12/1/2018, -   
US_367,PFP-A1049600,3/1/2019, -   
US_367,PFP-A1049600,6/1/2019, -   
US_367,PFP-A1049600,9/1/2019, -   
US_367,PFP-A1049600,12/1/2019, -   
US_367,PFP-A1049600,3/1/2020, -


Can JREPL be employed in this case? Otherwise, i was just going to run this through a for loop and then a find&replace method. Was hoping to use JREPL to do both, however.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Remove white spaces and replace "-" with 0 - JREPL?

#2 Post by dbenham » 29 Oct 2017 09:10

Of course. Here is the first solution that comes to mind:

Code: Select all

jrepl ",\s*-\s*$|,\s*(?=[^,]*$)" ",0|," /t "|" /f test.txt


Dave Benham

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Remove white spaces and replace "-" with 0 - JREPL?

#3 Post by SIMMS7400 » 29 Oct 2017 12:36

Hi Dave -

Works like a charm! Wow, thank you!

Thank you!

Post Reply