You are here: PSPad forum > English discussion forum > PScript help for a newbie...

PScript help for a newbie...

#1 PScript help for a newbie...

Posted by: Smonk | Date: 2022-03-18 07:59 | IP: IP Logged

Good Morning Guys!

kind of new to powershell and trying to make my life a bit easier with it smiling smiley

im using powershell to change date from a text file.

For now i have the (Get-content) -replace (Out-file) and that works perfectly.

This is what the text data looks like
ABC;;1;8888;;;11,00;;;413;
ABB;;1;7777;;;1,56;;;414;
AAA;;1;6666;;;60,00;;;412;
BBB;;1;5555;;;7,30;;;412;
CCC;;1;4444;;;19,00;;;412;
DDD;;1;3333;;;1,48;;;412;
EEE;;1;1222;;;46,25;;;416;
FFF;;1;1111;;;9,00;;;416;
KKK;;1;1234;;;45,11;;;413;
but I have been trying to get it to change (IF)
for example: If ABC has 8888 then 8888 should be change to 1234
From this: ABC;;1;8888;;;11,00;;;413;
to this: ABC;;1;1234;;;11,00;;;413; and the rest of the data should stay the same, and it should check line for line.

Is that even possible?

2nd thing i was trying to do is have the data from a secound text file be put at the first place of a diferent text file.
for example
File A:
12345;abcde;04/2022
File B:
ABC;;1;8888;;;11,00;;;413;
ABB;;1;7777;;;1,56;;;414;
AAA;;1;6666;;;60,00;;;412;
BBB;;1;5555;;;7,30;;;412;
CCC;;1;4444;;;19,00;;;412;
DDD;;1;3333;;;1,48;;;412;
EEE;;1;1222;;;46,25;;;416;
FFF;;1;1111;;;9,00;;;416;
KKK;;1;1234;;;45,11;;;413;

and I would like file B to end as
12345;abcde;04/2022
ABC;;1;8888;;;11,00;;;413;
ABB;;1;7777;;;1,56;;;414;
AAA;;1;6666;;;60,00;;;412;
BBB;;1;5555;;;7,30;;;412;
CCC;;1;4444;;;19,00;;;412;
DDD;;1;3333;;;1,48;;;412;
EEE;;1;1222;;;46,25;;;416;
FFF;;1;1111;;;9,00;;;416;
KKK;;1;1234;;;45,11;;;413;

is that possible?

Thank you very much for any tips or help you can give me

Have a great weekend guys

Regards
Smonk smiling smiley

Options: Reply | Quote | Up ^


#2 Re: PScript help for a newbie...

Posted by: pspad | Date: 2022-03-18 09:31 | IP: IP Logged

Because there is no other similar text, you can use regular expression in replace dialog
search for: (.*)(;\d{4};)(.*)
replace: $1;1234;$3
[x] Regular expressions

I put there intentionally semicolons, it's more readable.
$n means group in brackets, there are 3 groups

Options: Reply | Quote | Up ^


#3 Re: PScript help for a newbie...

Posted by: pspad | Date: 2022-03-18 09:36 | IP: IP Logged

regards to your second example
You want to put one line on the begin of file B, what is in the file A?
It's possible, but using PSPad scripting. If you are familiar with JScript, VBScript, you can switch on PSpad scripting in the program settings / System integration (in the 32b version only)
There is few scripts wheat can help you, help contains description too.

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR