How to replace intrementally?
-
Hello, @levente-horváth, @ekopalypse, @alan-kilborn,
Let give it a try with the
gawkutility !The
gawkutility reads each line of a file and splits it into different fields-
The option
-Fspecifies 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,,3different fields :-
Field
$1= The string"timestamp"preceded with2 spacechars -
Field
$2= The Unix timestamp1588464052 -
Field
$3= AnEMPTYstring
Now, it’s child’s play !
-
Create a new folder
-
Download the
gawk-5.0.1-w32-bin-ziparchive from https://sourceforge.net/projects/ezwinports/files/ , in that new folder -
Double-click on the
gawk-5.0.1-w32-bin-ziparchive -
Double-click on the
binfolder -
Extract, only, the
5filesgawk.exe,libgmp-10.dll,libmpfr-4.dll,libncurses5.dllandlibreadline6.dllin 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.txtNotes :
-
The file processed is the file
Input.txt -
Inside the
gawkprogram 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. -
Hi, @alan-kilborn and All,
I do understand the logic of your reasoning, Alan. In my defense, as this calculation couldn’t be done, natively, from notepad++, I thought I was entitled to propose this solution.
After all,
AWKis a scripting language just likePythonand it is possible to run an Gwak/Awk program, just using theRuncommand of Notepad++ ;-))For instance, using the example of my previous post :
-
Hit the
F5key, from within N++ -
Paste the command
cmd /c <ABSOLUTE Path to your GAWK.exe>\gawk -F": |," "/timestamp/ {$2 = $2 + 86400} ; {print > \"Output.txt\"}" Input.txtin the input zone -
Click on the
Runbutton
Note that, both, the
Input.txtfile processed and theOutput.txtfile created are located in the current Notepad++ folder, in case of portable installations of N++Nevertheless, I readily admit that the
Pythonplugin is closer to Notepad++ than theAWKprogram !Cheers,
guy038
-
-
@guy038 said in How to replace intrementally?:
I thought I was entitled to propose this solution.
Sorry for giving you a hard time about it. You are certainly entitled.
But, anyone here that has to install “something” additional to get to a solution is very likely better off just grabbing PythonScript. It’s easy to obtain (Plugins Admin), you don’t have to keep track of it separately (after install it will just “ride along” with Notepad++, and keep track of any scripts you use/write, and its a reasonably modern programming language. The same holds for LuaScript, I believe, although I am not a user of that.
Aside:
Just so you know, I hold no hatred of AWK.
There was a time before Python when I was into AWK.
This BOOK still adorns my bookshelves. -
Hello, @alan-kilborn,
Of course, it’s been more than
25years since I really practiceAWK. It was on anHP-Unixserver that would be laughed at, nowadays !I have already praised, several times, the precision and power of regexes, which, in a few words, produce great effects !
For the same reasons, it seems that I am simply impressed by the
AWKlanguage ;-))Cheers,
guy038