[CMD] Trying to extract some directory name in text file

Discussion in 'Mixed Languages' started by ar_seven_am, Dec 9, 2013.

  1. ar_seven_am

    ar_seven_am MDL Senior Member

    Mar 7, 2010
    398
    129
    10
    #1 ar_seven_am, Dec 9, 2013
    Last edited by a moderator: Apr 20, 2017
    Hi everyone, I'm trying to extract some directory name from an existing text file, for example the contain of mytext.txt is :

    Code:
    Drive : System
    List Directory : System:\Backup\Scripting\PHP\header.php
    List Directory : System:\Backup\Scripting\PHP\content.php
    List Directory : System:\Backup\Scripting\PHP\footer.php
    List Directory : System:\Backup\Scripting\HTML\header.php
    List Directory : System:\Backup\Scripting\HTML\content.php
    List Directory : System:\Backup\Scripting\HTML\footer.php
    
    someone can help so I can output only the content directory inside scripting (eg "PHP" and "HTML" without included the file inside)?

    the problem I faced is, using findstr need to know the string first, but here, "PHP" or "HTML" need to search by read mytext.txt...



    thx in advance...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. buyerninety

    buyerninety MDL Novice

    Oct 24, 2013
    10
    1
    0
    #2 buyerninety, Dec 11, 2013
    Last edited: Dec 11, 2013
    This all seemed to be pretty good advice...
    msfn.org/board/topic/170535-cmd-extract-specific-string-in-text-file/
     
  3. Mazzif

    Mazzif Elitebook Pwner

    Oct 18, 2013
    322
    441
    10
    #3 Mazzif, Dec 23, 2013
    Last edited by a moderator: Apr 20, 2017
    not sure if this is what your looking to do but:

    Crate a new bat file "filename.bat"

    Code:
    FOR /F "tokens=5 delims=\" %%i in (php.txt) do (
    ECHO %%i >> newfile.txt
    )
    when run from cmd:

    Code:
    H:\>test.bat
    
    H:\>FOR /F "tokens=5 delims=\" %i in (php.txt) do (ECHO %i  1>>newfile.txt )
    
    
    H:\>(ECHO header.php  1>>newfile.txt )
    
    
    H:\>(ECHO content.php  1>>newfile.txt )
    
    
    H:\>(ECHO footer.php  1>>newfile.txt )
    
    
    H:\>(ECHO header.php  1>>newfile.txt )
    
    
    H:\>(ECHO content.php  1>>newfile.txt )
    
    
    H:\>(ECHO footer.php  1>>newfile.txt )
    
    
    H:\>
    and will produce a text file call 'newfile.txt' that reads:
    Code:
    footer.php
    header.php 
    content.php 
    footer.php 
    header.php 
    content.php 
    footer.php 
    
    Hope that helps