Solved

Convert Unix Script to Windows Batch

Posted on 2014-10-29
3
210 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 68

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

896 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

17 Experts available now in Live!

Get 1:1 Help Now