Wild card again



  • Hi gurus.

    I am sure this has come up many times, but as I am very new to Notepad and its power I need to get some help while I get there.

    I have the following

    copy k:\apps\demex\system\ABBREV.DBF n:\apps\demex\system\ABBREV.DBF /Y

    I need the following

    I need to replace all and just leave the file meaning
    replace all and just leave ABBREV.DBF in this case but there are many lines and the file will not be the same

    I have tried
    find what: copy k:\apps\demex\system*.* but this not work

    so as you can see very new to all this

    Thanks for any help I can get



  • Hello Jose,

    If I fully understood what you want, you would like to get rid of the leading string copy k:\apps\demex\system\, on each line of your batch file, wouldn’t you ? Really easy, indeed !

    So, let’s imagine a part of your batch file, below :

    copy k:\apps\demex\system\ABBREV.DBF n:\apps\demex\system\ABBREV.DBF /Y
    copy k:\apps\demex\system\TEST.DBF n:\apps\demex\system\TEST.DBF /Y
    copy k:\apps\demex\system\"abc def ghi.DBF" n:\apps\demex\system\"abc def ghi.DBF" /Y
    copy k:\apps\demex\system\1234567890.DBF n:\apps\demex\system\1234567890.DBF /Y
    copy k:\apps\demex\system\Me.DBF n:\apps\demex\system\Me.DBF /Y
    

    Just notice that the name of the file, in the third line, contains spaces and, then, has been surrounded by double quotes ( " )

    Follow the few steps, below :

    • Open your batch file, in notepad++

    • Open the Replace dialog

    • Type, in the Find what zone copy k:\apps\demex\system\

    • Leave the Replace with zone EMPTY

    • Select the usual Normal search mode ( IMPORTANT )

    • Click on the Replace All button

    Et voilà ! You now get the text :

    ABBREV.DBF n:\apps\demex\system\ABBREV.DBF /Y
    TEST.DBF n:\apps\demex\system\TEST.DBF /Y
    "abc def ghi.DBF" n:\apps\demex\system\"abc def ghi.DBF" /Y
    1234567890.DBF n:\apps\demex\system\1234567890.DBF /Y
    Me.DBF n:\apps\demex\system\Me.DBF /Y
    

    Jose, feel free to ask me, if I’m wrong about it !

    See you later

    guy038

    P.S. :

    I’m wondering : don’t you miss some DOS command, at the beginning of each line of that final file ?!



  • If you just want the file names, you can use a Regular expression find and replace. I’m not a regex expert, but this worked for me:

    • Under Find what: ^.*\\(.+) n:.*$
    • Under Replace with: $1

    What this does is it matches an entire line (^ means the start of the line and $ means the end of the line). Within that line, it creates a capture group (the bit in parentheses, .+, which is one or more of any character) that is preceded by the part from the beginning of the line to a slash, and followed by a space followed by “n:” followed by zero or more characters to the end of the line. The $1 in Replace with means to replace with the contents of the first capture group.

    This will take you from

    copy k:\apps\demex\system\ABBREV.DBF n:\apps\demex\system\ABBREV.DBF /Y
    copy k:\apps\demex\system\TEST.DBF n:\apps\demex\system\TEST.DBF /Y
    copy k:\apps\demex\system\"abc def ghi.DBF" n:\apps\demex\system\"abc def ghi.DBF" /Y
    copy k:\apps\demex\system\1234567890.DBF n:\apps\demex\system\1234567890.DBF /Y
    copy k:\apps\demex\system\Me.DBF n:\apps\demex\system\Me.DBF /Y
    

    to

    ABBREV.DBF
    TEST.DBF
    "abc def ghi.DBF"
    1234567890.DBF
    Me.DBF

Log in to reply