0

Given a text file helloworld.txt containing the following line:

hello/world

The following sed command will output the file contents with the line removed:

sed '\:^hello/world:d' helloworld.txt

However if the command is run as a System.Diagnostics.Process:

var process = new Process
{
    StartInfo =
    {
        FileName = "sed",
        Arguments = "'\\:^hello/world:d' helloworld.txt",
        RedirectStandardOutput = true,
        UseShellExecute = false
    }
};
process.Start();
while (!process.StandardOutput.EndOfStream)
{
    Console.WriteLine(process.StandardOutput.ReadLine());
}
process.WaitForExit();

Then the output is "hello/world" (i.e. the matching line is not removed).

Why is this?

Owen Pauling
  • 11,349
  • 20
  • 53
  • 64
  • `Console.WriteLine("'\\:^hello\\/world:d' helloworld.txt");` outputs `'\:^hello\/world:d' helloworld.txt` for me, this is different than `'\:^hello/world:d' helloworld.txt`. – Quantic Mar 03 '17 at 17:46
  • @Quantic the question had a typo, sorry – Owen Pauling Mar 03 '17 at 17:50

1 Answers1

0

I was able to get this working by adding an additional backslash:

"'\\\:^hello/world:d' helloworld.txt"

Based on information found in this answer.

Owen Pauling
  • 11,349
  • 20
  • 53
  • 64