You are not logged in.
Hi, I have a problem with the output of bash commands. I'd like to print the result of a command like 'cut' to console without the newline character at the end, much like 'echo -n' does. It would be sufficient to find a command which eliminates the newline and doesn't put it back when it outputs the result, like 'sed' does. Is there an option to tell 'sed' to give its output without appendinga a newline?
Thanks
Last edited by snack (2010-10-20 10:50:59)
Offline
There will be a better method than this, I'm sure, but you could use awk:
awk '{printf $0}'
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
printf %s "$(your_cmd_here)"
or
echo -n "$(your_cmd_here)"
This silver ladybug at line 28...
Offline
Thank you both, I tried the solution of skanky and it worked perfectly.
Offline
Thank you both, I tried the solution of skanky and it worked perfectly.
In that case, you want
awk '{printf("%s",$0);}'
insead of
awk '{printf $0}'
Try:
echo '%s foobar' | awk '{printf $0}'
This silver ladybug at line 28...
Offline
Thanks lolilolicon, but awk '{printf $0}' works for my purpose, and it fits my needs (I havo to put it inside a cmake configuration file). I will also try your solutions, in case this stops to work.
Offline
Adding the %s is better practice and not doing so could well bite at some point in the future (esp. if you copy it to use elsewhere) - I was in a hurry earlier and hadn't thought my suggestion through properly.
Last edited by skanky (2010-10-20 12:06:02)
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline