Solved

Convert Unix Script to Windows Batch

Posted on 2014-10-29
3
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 70

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

696 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