Solved

Convert Unix Script to Windows Batch

Posted on 2014-10-29
3
205 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 19

Expert Comment

by:n2fc
Comment Utility
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 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
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
Comment Utility
Thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now