Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Aug 2014
    Posts
    123
    Thanks
    19
    Thanked 0 Times in 0 Posts

    '#' is not recognized as an internal or external command

    Doing compares and keep getting this exception regarding the # character. Cannot find an escape character for it so far.
    Is that my problem or is it elsewhere?
    Code:
    @echo off
    setlocal EnableDelayedExpansion
    
    set Ins="12345678910"
    set Fnd="echo #     []   # \"abcdefghijkl\"" 
    for /f "tokens=*" %%A in ("mytst.txt") do (
    if "%%A" EQU "%Fnd%" echo "%Ins%" >> myt2.txt
    if NOT "%%A" EQU "%Fnd%" echo "%%A"   >> myt2.txt
    )
    exit /b
    Tnx in advance for the help!

  2. #2
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,413
    Thanks
    33
    Thanked 195 Times in 175 Posts
    A bit difficult to test since you don't specify the contents of MYTST.TXT!

    I can't see offhand what could be objected to, but the usual escape character is ^

    Here's what I have used to test on Windows 7 (the enabledelayedexpansion being redundant):
    Code:
    setlocal
    set Fnd="echo #     []   # \"abcdefghijkl\"" 
    echo %fnd% > $$.txt
    notepad $$.txt
    endlocal
    and that gives in $$.TXT
    Code:
    echo #     []   # \"abcdefghijkl\"
    Is this what you expect?

    Later...
    Here's an ancient post about BATch file escape character sequences which might assist.
    In fact, have my whole Google search!
    Last edited by BATcher; 2015-04-18 at 07:58. Reason: Add links
    BATcher

    Time prevents everything happening all at once...

  3. The Following User Says Thank You to BATcher For This Useful Post:

    spark55 (2015-04-20)

  4. #3
    2 Star Lounger
    Join Date
    Aug 2014
    Posts
    123
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Thanks BATcher. I believe I copied the input file into some remarks at the beginning of the code.
    I thought the # might have been a character to escape but according to the reference (had it) it isn't listed to need ^'ing.
    I have solved the problem another way by using substringing and changing the border characters. This remains an open problem for me to solve later.

  5. #4
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,413
    Thanks
    33
    Thanked 195 Times in 175 Posts
    Trying to read text files into BATch file variables using FOR /F is fraught with problems if the text contains any so-called "poison characters", like % and & and " and so on. This snag pushes BATch files to the limits of practicality. Fortunately this is a fairly rare requirement!
    BATcher

    Time prevents everything happening all at once...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •