Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Sep 29 '11 at 11:03

This question came from our site for professional and enthusiast programmers.

up vote 0 down vote accepted

\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.

share|improve this answer
@Usavich : please see my final edits. I believe I have solved your problem exactly as requested. Good luck. – shellter Sep 29 '11 at 2:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .