Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-22-2015, 01:43 PM   #1
LQ Newbie
Registered: May 2015
Posts: 12

Rep: Reputation: Disabled
How to avoid newlines output in bash script

I am have a bash script like this:

while true;
(printf %s "$(date '+%A %W %Y %X')"; echo -n ", " ; printf %s "$(ps -eo pcpu,pmem,comm | grep statsd)") >> tope.txt;
sleep 2;

What I want is the output of this command be entered into tope.txt like this:

Friday 20 2015 11:28:21, 0.0 0.4 /usr/libexec/systemstatsd

but what I get is output like this in multiline. :

Friday 20 2015 11:28:21
0.0 0.4 /usr/libexec/systemstatsd

What can I do to fix this?
Old 05-22-2015, 02:32 PM   #2
LQ Addict
Registered: Dec 2013
Posts: 5,342

Rep: Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229
you can use one long printf command, i think it would go sth like this:
printf "%s, %s" "$(date '+%A %W %Y %X')" "$(ps -eo pcpu,pmem,comm | grep statsd)"
Old 05-23-2015, 05:30 AM   #3
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 820

Rep: Reputation: 197Reputation: 197
Why did you introduce a "echo -n" in the middle?



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 02:57 PM
[SOLVED] Removing newlines from output of cat command MahendraL Programming 5 12-20-2012 06:35 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 09:06 PM
[SOLVED] wget seems to add extra newlines on output to serial port? Schadrach Linux - Newbie 2 10-05-2010 02:59 PM
bash -c not working with newlines zagzagel Linux - Software 4 07-15-2010 12:39 PM

All times are GMT -5. The time now is 04:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration