none
Trying to isolate records with spaces in positions 37 through end of record BUT NON-SPACES FROM 1-36 (SOLVED) RRS feed

  • Question

  • Here is the DIR9.TXT file:

    Directory of C:\tmp\report scans\a 
    Directory of C:\tmp\report scans\b 
    Directory of C:\tmp\report scans\c 
    Directory of C:\tmp\report scans\c\a
    Directory of C:\tmp\report scans\c\a\Nobody, Joey

                                                           ^

                                                           This is position 37...

                                                           Ignoring spaces, from here to end of record is the text \Nobody, Joey 

    My goal is to isolate only the 4th record:    Directory of C:\tmp\report scans\c\a

    (or any record with spaces in pos 37 thru end of record BUT NON-SPACES FROM 1-36)

    To do this I thought I could use FINDSTR, but I couldn't figure out how to use the regular expressions.

    I also tried a script as follows:

    @echo off
    setlocal ENABLEDELAYEDEXPANSION
    for /f "tokens=*" %%i in ('type dir9.txt') do call :checker9     
    :checker9
    set check=!i:~36,2!
    if %check% EQU " " echo !i!)

    Obviously, I don't know what I'm doing.  This should be a simple no-brainer, but I can't figure out how to isolate all records with spaces

    in positions 37 through end of record.  Any record with spaces in positions 37 and 38 will also have spaces to end of record.

    Sorry for the large font.  Not sure how to reduce it.







    • Edited by t5404tmz Saturday, September 21, 2019 2:21 AM
    Friday, September 20, 2019 8:00 PM

All replies

  • Hello,

    If you can use PS, then maybe this one liner can help:

    PS D:\> Get-Content D:\test.txt | Select-String -SimpleMatch 'Nobody'
    
    Directory of C:\tmp\report scans\c\a\Nobody, Joey

    Additionally, you can use mighty RegEx (PS again):

    PS D:\> $a = Get-Content D:\test.txt
    PS D:\> $a -match '\\Nobody.+'
    Directory of C:\tmp\report scans\c\a\Nobody, Joey


    Cheers,

    Sok.


    • Edited by Sokratissz Friday, September 20, 2019 8:46 PM add code to code block
    Friday, September 20, 2019 8:35 PM
  • i should have been more specific.  The "\Nobody" is not the target.  The goal is to isolate records with a space in position 37 thru end of record BUT NON-SPACES FROM 1-36.

    But thanks for the help!


    • Edited by t5404tmz Friday, September 20, 2019 8:42 PM
    Friday, September 20, 2019 8:38 PM
  • If well understood, then this should work:

    PS D:\> ($a -match '\\Nobody.+').Substring(37)
    Nobody, Joey
    PS D:\> ($a -match '\\Nobody.+').Substring(37) -match ' '
    True

    Cheers,

    Sok.

    Friday, September 20, 2019 8:51 PM
  • i should have been more specific.  The "\Nobody" is not the target.  The goal is to isolate records with a space in position 37 thru end of record BUT NON-SPACES FROM 1-36.

    But thanks for the help!


    This can only be done efficiently with RegEx and PowerShell.

    $line -match '[a-zA-Z0-9]{35,35}\s+$'

    This functionality is not available in batch.


    \_(ツ)_/



    • Edited by jrv Friday, September 20, 2019 8:58 PM
    Friday, September 20, 2019 8:51 PM

  • This can only be done efficiently with RegEx and PowerShell.

    $line -match '[a-zA-Z0-9]{35,35}\s+$'

    This functionality is not available in batch.


    \_(ツ)_/



    Ok... I downloaded Powershell, I just don't know what to do next.  Can I run this command in the subdirectory with the file in it?  What is the syntax for my specific need to run it against file DIR9.TXT?
    Friday, September 20, 2019 9:06 PM
  • PowerShell is installed on all systems by default.  Just type Win-R and type "PowerShell" into the box and you will be in PowerShell.


    \_(ツ)_/

    Friday, September 20, 2019 9:13 PM
  • PowerShell is installed on all systems by default.  Just type Win-R and type "PowerShell" into the box and you will be in PowerShell.


    \_(ツ)_/

    Ok, I'm in Powershell

    I'm guessing I have to somehow use the command you gave me to filter my dir9.txt file.  I haven't figured out how to do that.

    And thanks for the assistance.  I really appreciate your help.  I can do some studying up on how it all works in my spare time, but right now I just need to filter my dir9.txt file to display or write to another file all of the records with spaces in 37-end of record.  And 1-36 cannot be leading spaces.

    Friday, September 20, 2019 9:25 PM
  • There are hundreds of PowerShell beginner videos on YouTube, Better yet you can buy a book and study.

    You can also ask someone to write a script for you here: https://gallery.technet.microsoft.com/scriptcenter/site/requests


    \_(ツ)_/

    Friday, September 20, 2019 9:36 PM
  • Please learn how to post scripts in this forum. You are just pasting junk that displays in HUGE letters and is unreadable. That will not get you an answer.

    See: How to post code in Technet Forums

    Also note that this is a professional forum and is not equipped to work with home users or kids.  There are other forums that are designed for that.  If you want help you need to post in a professional way observing the rules of the forum. 

    Note that the position you are referencing id the end of the line and has no spaces after it.  Rethink what you are doing based on thaaat information.  You may have to take some time to learn about files and how they are us3ed in com\putting as well as formats and what strings are.


    \_(ツ)_/

    Saturday, September 21, 2019 3:40 AM