Using PERL to append chars to each line

I tried using SED to do this, but I'm not having any luck with it. See the previous thread here.

I have a program called AMStracker (on OS X) that spits out the values of the motion sensor in the HDD. It has output that looks like this:

.
.
3 0 -75
3 0 -76
3 0 -77
.
.

I need to change it so that it looks like this:

.
.
3 0 -75;
3 0 -76;
3 0 -77;
.
.

ie. just add a ';' at the end of each line.

I was able to get the text _looking_ how I wanted with SED, but something was wrong that could not be seen. After filtering through SED I could no longer pipe the output into netcat (before filtering I could). I think that SED might be doing something to the line breaks?

Anyways, I tried using PERL instead of SED. I made the script below:

#!/usr/bin/perl

while (<>)  {
    $input = $_;
    $full = $input;
    printf("%s;\n", $full);
    }

But this gives me output like this:

.
.
;
23 0 12
;
22 0 13
.
.

Clearly I have the ';' before the '\n' in the script, but it does not appear that way in the output. All I can think of is that I need to strip the carriage return that comes with the input from AMStracker and then add my ';' and then replace the at the end of each line '\n'.

I suppose that using printf or sprintf will allow me to truncate the last byte of eac line that is coming in from AMStracker? How would I do this?

Help Please!

May be it happens becouse AMStracker writes to stderr, try something like

/amstracker -u 0.05 -s | sed 's/.*/&;/' 2>&1 | nc 127.0.0.1 5001

Well, first, no need start another thread on basically the same topic.

What exactly are you trying to accomplish? In the other thread, after someone posted a solution for your question, you added another kink to the issue. You need to explain the whole thing; otherwise, if you keep saying "oh this doesn't work because I have to do this also", I don't think you are going to get much help.

Now, being sed or perl, I think you are looking at the wrong side of the problem. Neither sed or perl are removing anything from the data. I think that the problem is with your usage of netcat.

To start, why are you trying to create a TCP connection to your localhost? That's what you are doing when you issue nc 127.0.0.1 5001. That makes no sense. You are already there.

So, explain exaclty what you are trying to do, from beginning to end.

Goodness gracious. Please state everything known to man before I will provide an answer.

Simple answer for simple question. Try using chomp.

#!/usr/bin/perl

while (<>) {
$input = $_;
chomp($input);
$full = $input;
printf("%s;\n", $full);
}

Goodness gracious. Why don't you read what was posted. This guy has started 3 threads on the same topic. The substitution of the character is not his issue. He thinks that is his issue, but it isn't. See, goodness gracious? His problem is that he's not seeing what he wants at the end of a command in which he gets a string of characters that then is piped into netcat. Ah! guess you need to know something more than what was posted. Go back and read the original thread he posted, goodness gracious.

BTW, goodness gracious, what you posted is not the simple answer. It's about 6 lines too long.

just a friendly reminder from the moderator.