Jump to content

Clean text file


Recommended Posts

Is there a way to clean this file up and only capture what's being displayed inside the parenthesis: EFV, EFC, Valve, Station, Regulator, etc (Material wording changes depending on input data from our operators)

I tried using the _ReplaceString function but it didn't work as expected. Certain things outside of the parenthesis were not being deleted or causing thing inside the parenthesis to be removed.

#include <file.au3>
_ReplaceStringInFile (@ScriptDir & "\Text.txt", "WordText", " ")
ClipPut (FileRead (@ScriptDir & "\text.txt"))

 

{"ParsedResults":[{"TextOverlay":{"Lines":[{"Words":[{"WordText":"EFV","Left":3.0,"Top":1.0,"Height":13.0,"Width":55.0},{"WordText":"EFC","Left":63.0,"Top":2.0,"Height":9.0,"Width":12.0},{"WordText":"Tap Tee","Left":81.0,"Top":1.0,"Height":10.0,"Width":49.0},{"WordText":"Valve","Left":135.0,"Top":1.0,"Height":10.0,"Width":51.0},{"WordText":"Station.","Left":192.0,"Top":1.0,"Height":10.0,"Width":18.0},{"WordText":"Regulator","Left":216.0,"Top":1.0,"Height":10.0,"Width":36.0},{"WordText":"Riser","Left":258.0,"Top":4.0,"Height":10.0,"Width":15.0},{"WordText":"Meter","Left":278.0,"Top":1.0,"Height":10.0,"Width":34.0},{"WordText":"Serviceline","Left":318.0,"Top":4.0,"Height":10.0,"Width":15.0},{"WordText":"Mainline","Left":338.0,"Top":4.0,"Height":7.0,"Width":14.0},{"WordText":"built","Left":358.0,"Top":1.0,"Height":10.0,"Width":28.0},{"WordText":"match.","Left":391.0,"Top":1.0,"Height":10.0,"Width":43.0},{"WordText":"Metersetting","Left":638.0,"Top":2.0,"Height":9.0,"Width":20.0}],"MaxHeight":13.0,"MinTop":1.0}],"HasOverlay":true,"Message":"Total lines: 1"},"FileParseExitCode":1,"ParsedText":"EFV EFC TapTee Valve Station\r\n","ErrorMessage":"","ErrorDetails":""}],"ExitCode":1,"IsErroredOnProcessing":false,"ErrorMessage":null,"ErrorDetails":null,"ProcessingTimeInMilliseconds":"1359"}

Trying to get something like this:

EFC
Valve
Regulator
Meter
Mainline
Metersetting

 

Edited by aa2zz6
Forgot to add something :|
Link to comment
Share on other sites

You can rewrite the code in the following example to get the data you want:

#NoTrayIcon

#include <Array.au3>
#include "JSON.au3"

Global $iJSON = '{"ParsedResults":[{"TextOverlay":{"Lines":[{"Words":[{"WordText":"EFV","Left":3.0,"Top":1.0,"Height":13.0,"Width":55.0},{"WordText":"EFC","Left":63.0,"Top":2.0,"Height":9.0,"Width":12.0},{"WordText":"Tap Tee","Left":81.0,"Top":1.0,"Height":10.0,"Width":49.0},{"WordText":"Valve","Left":135.0,"Top":1.0,"Height":10.0,"Width":51.0},{"WordText":"Station.","Left":192.0,"Top":1.0,"Height":10.0,"Width":18.0},{"WordText":"Regulator","Left":216.0,"Top":1.0,"Height":10.0,"Width":36.0},{"WordText":"Riser","Left":258.0,"Top":4.0,"Height":10.0,"Width":15.0},{"WordText":"Meter","Left":278.0,"Top":1.0,"Height":10.0,"Width":34.0},{"WordText":"Serviceline","Left":318.0,"Top":4.0,"Height":10.0,"Width":15.0},{"WordText":"Mainline","Left":338.0,"Top":4.0,"Height":7.0,"Width":14.0},{"WordText":"built","Left":358.0,"Top":1.0,"Height":10.0,"Width":28.0},{"WordText":"match.","Left":391.0,"Top":1.0,"Height":10.0,"Width":43.0},{"WordText":"Metersetting","Left":638.0,"Top":2.0,"Height":9.0,"Width":20.0}],"MaxHeight":13.0,"MinTop":1.0}],"HasOverlay":true,"Message":"Total lines: 1"},"FileParseExitCode":1,"ParsedText":"EFV EFC TapTee Valve Station\r\n","ErrorMessage":"","ErrorDetails":""}],"ExitCode":1,"IsErroredOnProcessing":false,"ErrorMessage":null,"ErrorDetails":null,"ProcessingTimeInMilliseconds":"1359"}'

Local $t, $sBreak
If StringInStr($iJSON, ",") Then
    $iJSON = StringRegExpReplace($iJSON, "[\[\]{}]", "")
    $sBreak = StringSplit($iJSON, ",")
    For $a = 1 To $sBreak[0]
        $t = _JSONDecode("{" & $sBreak[$a] & "}")
        _ArrayDisplay($t, "multi " & $a & " of " & $sBreak[0])
    Next
Else
    $t = _JSONDecode($iJSON)
    _ArrayDisplay($t, "single")
EndIf

 

JSON UDF HERE:

 

Regards,
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...