Add zeros to all blanks in row
-
I am hoping to automate a task in notepad++ with either a macro or a script of some sort to clean up the trailer row on a file.
The specific row has 147 columns of data and I want each position that is currently empty to instead contain a 0.
For example, something like this:
Total 862 5523 33211 (could be a varying number of spaces between each new set of data)
Would look like this:
Total00000862000000005523000000000033211
I wouldn’t want the remaining rows above to have this - just the last row. Is there a way to do this without manually adding each 0?
-
@Brian-Warmuth said in Add zeros to all blanks in row:
Is there a way to do this without manually adding each 0?
Not too difficult. this would need to be made a macro as it uses 2 different functions.
The first will read/consume all lines except the last one, leaving the cursor at the start of the last line. The second step then changes all spaces to zeros (only on the last line).So start the macro recording and then open the Find function. Enter
(?-s)(.*\R)+\K
, make sure search mode is “regular expression” and click on “Find Next”, then select the Replace Tab. The Find What field would now be a single space and the Replace With field is a single zero. Make sure the “Wrap around” button is NOT ticked and click on “Replace All”. Close. You could now stop the macro.Let us know if this solves your problem, or maybe it doesn’t and then we’d need to know how it missed on something.
Terry
-
That did it - thanks, Terry! Not sure why I was making it more complicated in my head than how you put it.
-
Well you may not have been aware of some of the power and functionality Notepad++ has at its disposal. Always good to ask a question like you did if your initial assessment/idea doesn’t pan out.
The members here are happy to help where we can.
Terry