1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Resolved Passing variable from BAT file through sed?

Discussion in 'Windows XP' started by Sduibek, 2011/06/07.

  1. 2011/06/07
    Sduibek

    Sduibek Inactive Thread Starter

    Joined:
    2008/09/10
    Messages:
    74
    Likes Received:
    0
    Hi,

    This is an example of what i'm looking to do:

    ECHO Please enter a number here, we'll use it later
    [user types 100 and presses Enter]
    [100 is stored as, let's say a variable "NumVar"]
    sed s/###/NumVar/ oldfile > newfile

    So basically the user is prompted via DOS .batch file commands to enter a value, the value is stored and then passed to sed as a string - the string being used as the "new text" sed will use when parsing and modifying the file.

    Is this possible?
     
  2. 2011/06/07
    Sduibek

    Sduibek Inactive Thread Starter

    Joined:
    2008/09/10
    Messages:
    74
    Likes Received:
    0
    A clearer example:

    ECHO What day is it today?
    Tuesday
    %StringVariable=Tuesday
    sed s/today/%StringVariable/ dailyreport.txt > dailyreportnew.txt


    Which would replace all instances of "today" with "Tuesday" within the target text file.
     
    Last edited: 2011/06/07

  3. to hide this advert.

  4. 2011/06/07
    wildfire

    wildfire Getting Old

    Joined:
    2008/04/21
    Messages:
    4,649
    Likes Received:
    124
    A while since I done batch files Sduibek but from what I recall you'll need to use choice, ergo the user can't type anything random but can select from a menu.

    As I said though, it's been a while, perhaps things have changed now but to be honest if you need that kind of user interaction a more suitable language would probably be a better option.
     
  5. 2011/06/07
    Sduibek

    Sduibek Inactive Thread Starter

    Joined:
    2008/09/10
    Messages:
    74
    Likes Received:
    0
    Fair enough. My first thought was VBScript or the ''Windows Script'' but the problem is I need this to work in Windows 7 and Windows Vista as well. Would those impose restrictions on vbs/ws running on non-Admin user accounts? I don't have those OSes personally but I know that they tend to be overzealous on security
     
  6. 2011/06/07
    wildfire

    wildfire Getting Old

    Joined:
    2008/04/21
    Messages:
    4,649
    Likes Received:
    124
    Depending on what you're trying to do but the worst case scenario would be UAC popping up asking to confirm. Obviously if you try anything that requires Admin privileges it wouldn't matter what development platform is in use, the user still must have rights or admin sets the rights for the software.
     
  7. 2011/06/08
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.