Need help converting UNIX shell script to DOS batch script

Discussion in 'Software' started by vanco2001, Apr 15, 2011.

  1. vanco2001

    vanco2001 Private E-2

    Hi, I have these few lines of shell script that I need to convert to DOS batch. Not sure if there is any way of doing the same. Please help me out with this.

    usr/bin/sed 's/\\\\/\\/g' /nesto/$FILENAME1 > /nesto/$FILENAME2
    /usr/bin/sed 's/\\\|/\|/g' /nesto/$FILENAME2 > /nesto/$FILENAME1
    /usr/bin/sed 's/*|//g' /nesto/$FILENAME1 > /nesto/$FILENAME
    /usr/bin/find /nesto/ -size 0 -exec rm {} \;
     
  2. theefool

    theefool Geekified

  3. theefool

    theefool Geekified

  4. PC-XT

    PC-XT Master Sergeant

    I'm not a sed expert, but if I understand it correctly, I don't know of a way to translate the whole thing purely into a DOS BATch file. You could do the first and last lines in batch, but not the other 2, afaik. There are workarounds and utilities, though. Here's the breakdown:

    Code:
    usr/bin/sed 's/\\\\/\\/g' /nesto/$FILENAME1 > /nesto/$FILENAME2
    This line could be done in a batch file, with code like shown at http://www.dostips.com/?t=Batch.FindAndReplace

    Code:
    /usr/bin/sed 's/\\\|/\|/g' /nesto/$FILENAME2 > /nesto/$FILENAME1
    /usr/bin/sed 's/*|//g' /nesto/$FILENAME1 > /nesto/$FILENAME
    These lines deal with | characters, which batch files generally cannot handle, (along with other operators like < or >.) The FOR command also cannot handle * as the first character of the string to match, since it matches any group of characters if it is the first character (rather than 0+ repetitions of the previous character in sed.) If you didn't need these 2 lines, you could do the others in a batch file.
    Alternatives include specialty replacement editors, Unix ports such as the sed download theefool gave, or using other languages like VBScript in this example (scroll to bottom after ads load)


    Code:
    /usr/bin/find /nesto/ -size 0 -exec rm {} \;
    The following url gives several ways to delete empty files in DOS:
    http://fixunix.com/ms-dos/335289-bat-file-delete-txt-files-size-0kb-text-file-empty.html
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds