Yea, this is easy, IF you use SED much. Now I updated this post with a Groovy approach, since this is easier to install where cygwin may be prohibited.
With cygwin installed, SED, the stream editor is available. In a command shell, execute:
Update: fixed the sed above, was missing the backslash before the n.
- set path will print the Windows path. File path entries are separated by “;”.
- sed will invoke the cygwin installed linux SED command. Cygwin\bin is part of the executable path.
- “s” indicates the substitute command
- “_”, the underscore is used as the delimiter to each part of the substitution. One can use other characters for the delimiter.
- “;” is the regular expression to use for a match.
- “;\n” is the string to substitute with. \n is the crlf.
- “g” is the substitute flag, global replacement
No doubt there are more direct ways of doing this. Using PowerShell would be the most appropriate on Windows if it is available.
Another approach is using the Groovy language, which has a command line mode using the “-e” switch:
The output of set path is piped to an inline Groovy script. The script uses the “text” value of the System.in standard input stream. ‘text’ is some magic Groovy dust. The Groovy development kit (GDK) extends Java io streams with a method, textO(), that gets the string value of the stream, like read a file. This is available as a java bean getter method, which again via magic is available as a field, “.text”. The string is then split, then a closure “each” is used to print each line, passed to the closure with the default variable “it”.
If your path is: C:\fee;d:\fi;c:\foo;fum
The result would be:
You can, of course, pipe these together to allow finer control. However, the high level language makes for very long winded code, for example, find all properties in Java system properties that have the word ‘Java’ or ‘java’:
Better would be, just putting the filtering inside the closure:
Or as a script:
Consult the Groovy documentation for further Groovy syntax and idioms to make the above even better.