Most popular tags

Welcome to, where you can ask questions and receive answers from other members of the community.

cat file that contains escaped characters to netcat

I'm trying to test a webserver with some HTTP request written in a file.

GET / HTTP/1.1\r\n\r\n

Right now I'm feeding that file to netcat like this:

cat files | nc localhost 80

However, the \r\n in the files are transfered directly to webserver(resulting in 4 chars, i.e. '\','r','\','n'). How can I feed that file so that chars are escaped correctly?

1 Answer

\r\n are the codes used in a printf statement to generate CarridgeReturn/NewLine line endings used by DOS/Windows.

As you are using cat, you are using some variant of unix which only uses \n as line end. BUT you don't have to have that char appear in the file. Just try removing those values (leaving a real Newline at the end of the line).

Example test file now =

GET / HTTP/1.1

GET / HTTP/1.1

OR if you really must interpret the \r\n values embedded in the file, you can interpret the file with the printf utiltity, i.e.

$ cat printf_inputtest.txt
GET / HTTP/1.1\r\n\r\n
GET / HTTP/1.1\r\n\r\n
$ printf "$( < printf_inputtest.txt )"
GET / HTTP/1.1

GET / HTTP/1.1


I hope this helps.