S
S
stepanof232020-07-21 18:19:52
PowerShell
stepanof23, 2020-07-21 18:19:52

How to escape I/O redirect characters in cmd?

I have a file.txt which contains:
< Hello World >
How can I extract the string Hello World from this file without special characters?

The file cannot be read and truncated due to I/O redirection characters ( < and > ).

I know there's an escape character ^, but it doesn't really help when reading a line from a file.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
azarij, 2020-07-21
@stepanof23

((get-content C:\test\hello.txt) -replace "[^a-zA-Z0-9 -]").trim()

M
MaxKozlov, 2020-07-22
@MaxKozlov

You can also use CMD if you wish :)
something like that

for /f "tokens=*" %%a in ('type "test.txt"') do (
  call :extract "%%a"
)
goto :EOF
:extract
set l=%1
@set "line2=%l:~2,-2%"
echo %line2%
goto :EOF

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question