Anyone good with text files?

If you do this quite often (and you use Windows), use this powershell script:

Code:
$input = Get-Content C:\Script\input.txt

$output = "C:\Script\output.txt"

foreach ($a in $input){

    $line = $a | Out-String

    $trimstart = $line.Remove(0,5) | Out-String

    $trimend = ($trimstart.Remove(5) | Out-String).Trim()

    Add-Content -Path $output -Value $trimend

}
 
Any decent text editor + regex? Something like /^.+, (\d+?),.+$/\1/g should do, I think (un-tested).
regular_expressions.png
 
If you do this quite often (and you use Windows), use this powershell script:

Code:
$input = Get-Content C:\Script\input.txt

$output = "C:\Script\output.txt"

foreach ($a in $input){

    $line = $a | Out-String

    $trimstart = $line.Remove(0,5) | Out-String

    $trimend = ($trimstart.Remove(5) | Out-String).Trim()

    Add-Content -Path $output -Value $trimend

}

Wont work because the initial number is almost certainly going to increment beyond "9" and shift your hard-coded starting positions. But good suggestion to use Powershell and example! OP really needs to explain the context for this. Given the question they probably don't know even how to create a runnable Powershell script. The format of the text makes me suspect it fell off the edge of an incomplete software solution. For all we know, two lines of Python added somewhere will get the OP the actual data they want to begin with!
 
Nice that you gave a regex for every column and explained how to pick out a column of choice. I'm concerned by the OP's comment that they need to do this for "files". I hope the OP isn't planning to regularly do this. If so, I think something has gone wrong as the sample file is clearly meant to be read programmatically so the OP is working with an incomplete solution, I suspect.

Good point. There are also command line tools like json2csv (I've never used it, but it came up on a quick Google) which would probably be better in this situation if it's a regular thing!
 
Wont work because the initial number is almost certainly going to increment beyond "9" and shift your hard-coded starting positions. But good suggestion to use Powershell and example! OP really needs to explain the context for this. Given the question they probably don't know even how to create a runnable Powershell script. The format of the text makes me suspect it fell off the edge of an incomplete software solution. For all we know, two lines of Python added somewhere will get the OP the actual data they want to begin with!

Ah, good point! (lazy coding for you). I've updated it just for you :P

Code:
$input = Get-Content C:\Script\input.txt

$output = "C:\Script\output.txt"

foreach ($a in $input){

    $line = $a | Out-String

    $pos = $line.IndexOf(",")

    $line1 = $line.Substring($pos+1)

    $trim = $line1.Split(',')[0]

    $result = $trim.Trim()
    
    Add-Content -Path $output -Value $result
    
}
 
tyvm guys, excels working brilliantly, i dont know why i didnt download this years ago haha. ty

it's amazing what excel can do.

although a better solution if there's lots of these is to look at where they're coming from, i had the same thing with a tensile tester before i figured out you could output directly to excel files.
 
Sed and awk have saved me so much time over the years. <3

Hate Perl though. It is the devil's work.
 
KISS is very relevant to this thread I think. :p

How to make a simple task of dragging a sheet into excel and extracting numbers that any layman could do into a spending hours learning code to do the same thing. :D

Do this kind of thing daily OP and excel is definitely the fastest and easiest way of doing it!
 
KISS is very relevant to this thread I think. :p

How to make a simple task of dragging a sheet into excel and extracting numbers that any layman could do into a spending hours learning code to do the same thing. :D

Do this kind of thing daily OP and excel is definitely the fastest and easiest way of doing it!
Haha very true.
 
Back
Top Bottom