Help with script

Hello all,

Iam making a script to extact some info from a text file. 

The folloing script extracts \\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0143.T and \\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0144.TIF from text file.

foreach ($file in $files)
{
$file1=$file.Name
#echo $file1
$reader=[System.IO.File]::OpenText("C:\Users\camone\Desktop\teste1\$file1")
#$line.Split(":",$option)[3]
#$reader = [System.IO.File]::OpenText("C:\Users\camone\Desktop\teste\$file1")
try {
    for(;;) {
        $line = $reader.ReadLine()
       if ($line -eq $null) { break }
         #process the line
        #$option = [System.StringSplitOptions]::RemoveEmptyEntries
        $option = [System.StringSplitOptions]::none
        #$line.Split(":",$option)[3]
        $line.Split(":")[3]
#        echo ........
    }
}
finally {
    $reader.Close()
}
}

So my problem is with example1 text beacause it has an enter and i cant retrieve all file information. My output will be  "C:\Support\Scripts\terminados\copy_0057.log-error.log:3:\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0143.T" instead of "C:\Support\Scripts\terminados\copy_0057.log-error.log:3:\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0143.TIF". 

Can anyone tell me how can i achieve the desired output?

Example1:

C:\Support\Scripts\terminados\copy_0057.log-error.log:3:\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0143.T
IF

Example2:

C:\Support\Scripts\terminados\copy_0057.log-error.log:3:\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0144.TIF

Regards,

Arestas

June 30th, 2015 7:01am

Any help is welcome.

Regards,

Arestas

Free Windows Admin Tool Kit Click here and download it now
June 30th, 2015 9:06am

Hi Arestas,

PLease refer to the script below, it is not elegant but works:

$t=gc d:\1.txt
for($i=0;$i -lt $t.count;$i++){
if ($t[$i] -eq $null) { break }
if(($t[$i] -match ":") -and ($t[$i] -notmatch "TIF")){$txt=$t[$i++]+$t[$i];$t[$i]=$txt}
$t[$i].Split(":")[3]
}

The input text list like:

C:\Support\Scripts\terminados\copy_0057.log-error.log:3:\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-

0057_m0142.TIF

C:\Support\Scripts\terminados\copy_0057.log-error.log:3:\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-

0057_m0143.T
IF

C:\Support\Scripts\terminados\copy_0057.log-error.log:3:\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-

0057_m0144.TIF

If there is anything else regarding this issue, please feel free to post back.

Best Regards,

Anna Wang

June 30th, 2015 11:30pm

Works like a charm.

Tks for your help Anna.

Regards,

Arestas

Free Windows Admin Tool Kit Click here and download it now
July 1st, 2015 7:43am

Need help with another thing.

\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0144.TIF how can i transform it in \LDA\CA\0057\ ??

For the first part is easy. i ll use TRIM Trim("\\smatrizes\smatrizes") but for the EN-XL-TAS-IC-0057_m0144.TIF have no idea how to do it since the text change from line to line. Basically i want to remove from end till it finds the "\".

Once again tanks for all the help.

Regards,

Arestas

 



  • Edited by Arestas 15 hours 52 minutes ago
July 1st, 2015 11:09am

Hi,

Here's something you can play with:

$str = '\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0144.TIF'
$str = $str.Replace('\\share\temp','')
$strFixed = $str.Substring(0,$str.LastIndexOf('\')+1)

$strFixed

Free Windows Admin Tool Kit Click here and download it now
July 1st, 2015 1:41pm

Need help with another thing.

\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0144.TIF how can i transform it in \LDA\CA\0057\ ??

For the first part is easy. i ll use TRIM Trim("\\smatrizes\smatrizes") but for the EN-XL-TAS-IC-0057_m0144.TIF have no idea how to do it since the text change from line to line. Basically i want to remove from end till it finds the "\".

Once again tanks for all the help.

Regards,

Arestas

 



  • Edited by Arestas Wednesday, July 01, 2015 3:15 PM
July 1st, 2015 3:08pm

Need help with another thing.

\\share\temp\LDA\CA\0057\EN-XL-TAS-IC-0057_m0144.TIF how can i transform it in \LDA\CA\0057\ ??

For the first part is easy. i ll use TRIM Trim("\\smatrizes\smatrizes") but for the EN-XL-TAS-IC-0057_m0144.TIF have no idea how to do it since the text change from line to line. Basically i want to remove from end till it finds the "\".

Once again tanks for all the help.

Regards,

Arestas

 



  • Edited by Arestas Wednesday, July 01, 2015 3:15 PM
Free Windows Admin Tool Kit Click here and download it now
July 1st, 2015 3:08pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics