Script to move a filed in a text file

I don’t know if this is possible as I think it would be rather complicated.

I have a file called ‘in’ which I have attached as an example. In the file there is a claim number that is on the following lines.
After the first claim number on line 17 it moves between line 50, 51 and 52 which depends on how big the address field is.

What I would like is some form of a script that would make sure that the claim number is in the same position for every record every time.

Something like a powershell or batch script should do the job.

This would be greatly appreciated.



Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
I'm not sure exactly what this mean:

"What I would like is some form of a script that would make sure that the claim number is in the same position for every record every time."

luketrAuthor Commented:
There is a claim number that is on the follwoing line numbers. But can it change its position depending on the length of the address filed.


I need a script that will move the claim number so it appears on the follwoing lines.


So if the 2nd record is on line 67 the script would move it to line 68.

After the first record which is always on line 17 the next record and so on need to appear every 51 lines.

I hope this makes sense.


Using the data in the relevant lines...can you tell me what you need to move around?  For instance, I see, on line 17,
11111       MR J BLOGGS                 1 ANY ROAD                     

Open in new window

Do you want the whole line (all of what's shown above) or just the Claim number (the numeric value) moved?  Also, do you want it replicated in position B (line 5-52 in your first post) or moved from position A (line 17) to position B (line 50-52 in your first post)?  Can you give an example of what position B looks like now and what you want it look like after the script has run?  Using the specific data from your example file will help make it more clear what you want.  Also, if there are exceptions (such as extra lines in the address) that need to be considered, put this as parameters.
The following basically finds all lines (one line after the word Claim appears) and searches for the next line first non-space value:
$filecontent = gc .\in.txt
$filecontent | Select-String "Claim" | select linenumber | foreach($line in $lines) { $filecontent[($line.linenumber+1)].Split(" ")[0]}
foreach($line in $lines) {$filecontent[($line.linenumber+1)].Split(" ")[0]}

Open in new window

If you found any $nulls you would know if there were lines that did not start with Claim numbers. You can build your logic from there.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.