Solved

Convert Unix Script to Windows Batch

Posted on 2014-10-29
3
212 Views
Last Modified: 2014-11-03
I have the following script that gets invoked a program, it invokes the script, makes the changes, and then reads the file back into the program. The script works for Unix, but I now need to have the same type of script for window.

#!/bin/ksh
cp $1 /tmp/tmpfile.$$
sed -e 's/OWNER root/OWNER nobody/' /tmp/tmpfile.$$ > $1

Appreciate the assistance in advance.
0
Comment
Question by:PAH_in_MI
3 Comments
 
LVL 20

Expert Comment

by:n2fc
ID: 40411348
The UNIX "sed" command is the issue... Nothing native in DOS like it...

You can install the GnuWin32 package, though

See: http://gnuwin32.sourceforge.net/

And be able to run sed on the windows box... Then just change your script as follows:

copy %1 %TEMP%\tmpfile.$$
sed -e "s/OWNER root/OWNER nobody/" %TEMP%\tmpfile.$$ > %1

All you would need to do is download the "sed" component and place in a directory that is in your path...

Download EITHER:
1) The sed setup file:
http://sourceforge.net/projects/gnuwin32/files//sed/4.2.1/sed-4.2.1-setup.exe/download

or
2) The bin & dependent DLL's:
http://sourceforge.net/projects/gnuwin32/files//sed/4.2.1/sed-4.2.1-bin.zip/download

http://sourceforge.net/projects/gnuwin32/files//sed/4.2.1/sed-4.2.1-dep.zip/download
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40414678
You can't perform that simple replacement inside your application? Sounds strange.
The pure DOS Prompt way is:
@echo off
setlocal EnableDelayedExpansion
copy %1 %TEMP%\tmpfile.$$
(for /F "tokens=*" %%L in (%TEMP%\tmpfile.$$)  do (
  set line=%%L
  echo,line=!line:OWNER root=OWNER nobody!
)) > %1

Open in new window

But that can fail if certain characters are contained in the lines to parse. Usual recommendation is to use chgstr.exe from http://www.paulslore.com/index.php?option=com_content&task=view&id=49&Itemid=46
0
 

Author Closing Comment

by:PAH_in_MI
ID: 40419311
Thank you.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question