Can batch file itself have sed like function?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Can batch file itself have sed like function?

#1 Post by goodywp » 01 Feb 2018 12:44

Hi All,

I had one piece code which used sed in batch file. Now due to sed is not a native utilities in windows. When I implement my code in Windows server 2012 R2, I got this issue:
'sed' is not recognized as an internal or external command.
I know there is two options:
either I install sed utility in server 2012 R2, I need to find it out
or change the following code to pure batch file

Could you please help me on the second option if possible?
Only read first and second lines from an old file which must have more then two lines then output into a new file...

Code: Select all

@ECHO OFF
cd C:\auto_pkg_build\Scripts\scheme_replace\pkg_data\temp

if exist newdata_1.txt (del newdata_1.txt)

sed -n -e 1p -e 2p echo_data_1.txt > newdata_1.txt

Thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can batch file itself have sed like function?

#2 Post by aGerman » 01 Feb 2018 14:33

There is no equivalent command in pure batch. Whether or not you can work around depends on the content of your sed scripts that you passed using -e and the content of the text file you used.
But on the other hand sed works without any installation. All you have to do is saving it in the same folder along with your batch script and the DLLs it depends on. Both the binary and the dependencies can be downloaded as zip files. You'll find them in the bin subfolder.
http://gnuwin32.sourceforge.net/packages/sed.htm

Steffen

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: Can batch file itself have sed like function?

#3 Post by goodywp » 02 Feb 2018 12:52

Thanks Steffen!

Post Reply