I have a .txt file that contains various lines of data which is organised by text starting at specific column numbers - basically a table of data.
The below example shows where each column starts:
I would like the script to find all lines which contain "-" in column 555 and replace this with the first 19 characters found in column 450 without effecting any line spacing.
Desired output for this example:
As you can see "Brooklyn" has been copied from column 450 and replaced the "-" in column 555.
Please note:
- The script will need to run through multiple .txt files located in the same folder
- The .txt files contain various number of lines e.g some files might have 20 lines whereas others may have 100
Also, In regards to checking each .txt in a given folder - I will be using the below. Please let me know if it possible with this.
Get-ChildItem C:\Users\Desktop -Filter *.txt |
ForEach-Object {
Set-Content $_.FullName) }
Could someone please help with scripting this in PowerShell.
Thank you in advance!
this is really rather ugly, but it seems to do the job. [grin]
output ...
what it does ...
as requested, here's a full script that handles reading the files & writing out the changes. it does NOT overwrite the source files, but the comments tell one how to make that change.