ZTree.com  | ZEN  | About...  

 Index   Back

command line SED   [Help!]

By: Ben Kent       
Date: May 22,2019 at 04:55
In Response to: command line SED (Neil Clough)

> > If using the command line is possible, then download sed from
> > http://gnuwin32.sourceforge.net/packages.html and use this
> commandline
> >
> > type input.txt | sed.exe -e ":x ; /\$$/ { N ; s/\$\n//g ; bx }"
> >
> > output.txt
> >
> > That sed syntax came from here
> > https://www.gnu.org/software/sed/manual/sed.html#Multiline-techniques
> >
> >
> > Ben
>
> Hi Ben,
>
> Thanks for tip but I am at work so probably not allowed to
> download/install SED.
>
> Not worth the hassle of asking.
>
> Cheers,

Neil

Then use powershell

In one line from outside of powershell, with a different output file
powershell -command "[IO.File]::WriteAllText('output.txt',([IO.File]::ReadAllText('input.txt') -replace '\$\r\n', ''))"

From inside powershell replacing the original file
$file = 'input.txt'
$text = [IO.File]::ReadAllText($file) -replace '\$\r\n', ''
[IO.File]::WriteAllText($file, $text)


If the use of powershell is blocked, but you can run cscript.exe, then I have a small JScript script that can to string replace http://www.ztw3.com/upfile/strreplace.zip, use like this

type input.txt | cscript.exe //nologo strreplace.wsf "\$\n" "" g > output.txt


Ben

113 views      
 

Messages in this Thread

 
94,417 Postings in 11,916 Threads, 348 registered users, 5 users online (0 registered, 5 guests)
Index | Admin contact |   Forum Time: Aug 22, 2019 - 9:28 pm EDT  |  Hits:28,555,927  (4,726 Today )
RSS Feed