How to replace intrementally?
-
@Alan-Kilborn There are thousand of timestamps like this and want to change them to the current day always.
"timestamp": 1588464027, }, { "timestamp": 1588464027, }, { "timestamp": 1588464027, }, { "timestamp": 1588464027, }, { "timestamp": 1588464052, }, { "timestamp": 1588464052, }, { "timestamp": 1588464052, }, { "timestamp": 1588464052,
-
What comes immediately to my mind are questions like
Current day but keeping time?
Current day and current time?
Current day and fixed other time? -
@Ekopalypse These are I believe times from 05. 03. 02:00 to 04:32. I want to change them to 05. 04. 02:00 to 04:32. I don’t need a program or anything just how can I do them manually? They increment in 25.
-
those timestamp look like unix timestamps, if this is the case then you can simply add 86400 seconds to it.
-
@Ekopalypse How can I highlight all of them, there are 1500 timestamps, 4 of each and they are similar til 1588. But I’m an idiot of not thinking adding 86400, this was a big help already and gave me some ideas.
-
If you only want to highlight them then use
find dialog, goto mark tab, use the following regex\d{10}
check regular expression in search mode and press mark all -
@Ekopalypse This is great, and how can I add 86400 to all of them? :')
-
because you said
I don’t need a program or anything just how can I do them manually?
the obvious answer would be by typing in the sum of the existing value
and 86400 but I get the impression that you want to do something
slightly different. I assume you want to select all timestamp
instances and then automatically add 86400 to them, correct?
If so, then you need some kind of script/program. If not, then
I still haven’t understood how you want to change these timestamps. -
@Ekopalypse Yes that’s correct, I thought it would be easy, now I have every timestamp selected and I thought with the replace or Column Editor I can add 86400 to all of them.
-
@Levente-Horváth What if I do Find What: \d{10}, and Replace With: \d{10}+86400
-
No, you do not have it selected, you just highlighted it, this is different and no, regex is not a calculator.
If you have to do such things more often then I would recommend to
install one of the scripting plugins like PythonScript, LuaScript and create
a little script to do this for you.
If you want to go that way we certainly can give you help solving this. -
@Levente-Horváth said in How to replace intrementally?:
Replace With: \d{10}+86400
I thought @Ekopalypse makes it clear above that things DO NOT work that way.
-
@Ekopalypse Then I will do it that way, whatever it takes.
-
So you are going to install, e.g. PythonScript plugin via the plugin admin?
If yes, what should the script do? Just add one day aka 86400 seconds?
Or more flexible like you’ve been asked to enter the seconds you want to add? -
@Ekopalypse I just want to add 86400 to the existing numbers.
-
ok, once you installed PythonScript, goto plugins->Python Script->New Script
give it a meaningful name and save it.
Paste the following into the newly create document and save it.from Npp import editor def add_a_day(m): return int(m.group(0)) + 86400 editor.rereplace('\d{10}', add_a_day)
Goto to plugin->Python Script->Scripts and execute your newly created script.
If you want to add it to the toolbar play with the configuration menu of pythonscript.
-
@Ekopalypse said in How to replace intrementally?:
editor.rereplace(‘\d{10}’, add_a_day)
Perhaps the OP’s data contains other 10 digit numbers, not related to timestamps??
I might go with this instead:
editor.rereplace('"timestamp": \K\d{10}', add_a_day)
Ensures that we are only changing the timestamp values.
-
@Alan-Kilborn No, it doesn’t contain any other 10 digit number, but I thank all of you, it works!
-
Hello, @levente-horváth, @ekopalypse, @alan-kilborn,
Let give it a try with the
gawk
utility !The
gawk
utility reads each line of a file and splits it into different fields-
The option
-F
specifies the separator(s) of the fields. As the value of that option is: |,
then, the separators are :- A colon, followed with a space char
OR - A comma
- A colon, followed with a space char
which defines, in specific lines
"timestamp": 1588464052,
,3
different fields :-
Field
$1
= The string"timestamp"
preceded with2 space
chars -
Field
$2
= The Unix timestamp1588464052
-
Field
$3
= AnEMPTY
string
Now, it’s child’s play !
-
Create a new folder
-
Download the
gawk-5.0.1-w32-bin-zip
archive from https://sourceforge.net/projects/ezwinports/files/ , in that new folder -
Double-click on the
gawk-5.0.1-w32-bin-zip
archive -
Double-click on the
bin
folder -
Extract, only, the
5
filesgawk.exe
,libgmp-10.dll
,libmpfr-4.dll
,libncurses5.dll
andlibreadline6.dll
in this new folder -
Open a DOS console window
-
Go to your
gawk
’s folder -
Run the following command :
gawk -F": |," "/timestamp/ {$2 = $2 + 86400} ; {print > \"Output.txt\"}" Input.txt
Notes :
-
The file processed is the file
Input.txt
-
Inside the
gawk
program section"........."
, any double quote"
must be escaped with a\
symbol -
If current line contains the string
timestamp
, then thefield 2
’s value is increased by86,400
-
In all cases, the resulting entire current line is rewritten in file
Output.txt
Best Regards,
guy038
-
-
@guy038 said in How to replace intrementally?:
Let give it a try with the gawk utility !
Please, let’s not.
Only when there isn’t a reasonable way, within Notepad++.
And one of those has already been provided.