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?
wls3Connect With a Mentor Commented:
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.
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.