LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-22-2015, 02:43 PM   #1
salilsurendran
LQ Newbie
 
Registered: May 2015
Posts: 9

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


I am have a bash script like this:

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

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, 03:32 PM   #2
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,159

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

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

OK
 
  


Reply


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 03:57 PM
[SOLVED] Removing newlines from output of cat command MahendraL Programming 5 12-20-2012 07:35 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 10:06 PM
[SOLVED] wget seems to add extra newlines on output to serial port? Schadrach Linux - Newbie 2 10-05-2010 03:59 PM
bash -c not working with newlines zagzagel Linux - Software 4 07-15-2010 01:39 PM


All times are GMT -5. The time now is 01:17 AM.

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