I'm trying to send a file, line by line, with the following commands:
nc host port < textfile
cat textfile | nc host port
I've tried with tail and head, but with the same result: the entire file is sent as a unique line. The server is listening with a specific daemon to receive data log information.
I'd like to send and receive the lines one by one, not the whole file in a single shot.
How can I do that?
Do you HAVE TO use netcat?
can also serve your purpose, at least with bash.
Try
Just guessing here, but you probably CR-NL end of lines:
Use stdbuf -oL to adjust standard output stream buffering. If MODE is 'L' the corresponding stream will be line buffered:
OP was unclear on whether they needed a new connection for each line. But based on the OP's comment here, I think their need is different than mine. However, Google sends people with my need here so here is where I will place this alternative.
I have a need to send a file line by line over a single connection. Basically, it's a "slow"
cat
. (This will be a common need for many "conversational" protocols.)If I try to cat an email message to
nc
I get an error because the server can't have a "conversation" with me.Now if I insert a
slowcat
into the pipe, I get the email.The
email_msg.txt
looks like this: