1
Here is the structure of my file:
g-4.n.g.fr 10.147.243.63 g-4.n.g.fr-w1
Here is my script:
#! /bin/sh
ip=10.147.243.63
worker=$(grep -e $ip $1 | awk '{ print $3; }')
echo "[Hostname: ]"
echo $worker
echo "[Before concat]"
echo $worker
echo "[After concat]"
echo "$worker.v.1"
I have this output:
[Hostname: ]
g-4.n.g.fr-w1
[Before concat]
g-4.n.g.fr-w1
[After concat]
.v.1n.g.fr-w1
I want to have .v.1
after g-4.n.g.fr-w1
without substitution, like this:
g-4.n.g.fr-w1.v.1
How can I modify my script to have this output?
Let us continue this discussion in chat.
– bertieb – 2015-07-03T14:40:38.690Hi, please is there another way to do this treatement : worker=$(grep -e $ip $1 | awk '{ print $3; }') i'd like to avoid grep. Thanks you so much.Kind Regards. – researcher – 2015-07-04T10:15:53.647
it works now. i have converted the input file to UNIX format first.. – researcher – 2015-07-04T14:23:16.553
1My apologies, I was away for the weekend. Glad you got something sorted eventually; and my guess about encoding wasn't too far off the mark :) – bertieb – 2015-07-06T12:06:34.417
While quoting all shell variables, and using
printf "%s"
instead ofecho
(especially for unknown strings), are good ideas, they do not make sense as answers to this question. Correcting/eliminating or otherwise dealing with the non-Unix line endings (i.e., CRLF) is the answer. @researcher: If you figured that out by yourself, you should post an answer of your own explaining that, and then accept that answer. While it is of course your decision which answer (if any) to accept, it is contrary to the intent of the checkmark to use it as a “thank you” for participation. … (Cont’d) – G-Man Says 'Reinstate Monica' – 2015-08-18T15:23:00.960(Cont’d) … You really shouldn’t give it to somebody just because he spent time trying to help you, if he didn’t actually contribute to solving your problem. And, if bertieb did, somehow, provide that solution (and I don’t see it on this page or in the chat), then it should be edited into his answer. One of Super User’s goals (and of the Stack Exchange network in general) is to build a knowledgebase; a repository of questions and their answers. It is of little benefit to future readers to “accept” an answer that does not answer the question (even if the answer is hidden in the comments). – G-Man Says 'Reinstate Monica' – 2015-08-18T15:23:30.577
@G-Man thanks for the rather long feedback, edited. – bertieb – 2015-08-18T15:36:44.453
Well, silver bullets are nice, but it would be better if you explained why CRLF line terminators produce the results that researcher was seeing. – G-Man Says 'Reinstate Monica' – 2015-08-18T15:40:47.893
@G-Man I'll try to get around to it, meantime feel free to edit it yourself.
– bertieb – 2015-08-18T15:42:54.637