LinuxQuestions.org
Visit Jeremy's Blog.
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 07-09-2014, 03:42 PM   #1
klaus-3140
LQ Newbie
 
Registered: Jul 2014
Posts: 2

Rep: Reputation: Disabled
Cool How to avoid LF when redirecting output with Tee or >


I have a script (Bash) that goes through many many pictures and to see the progress I have a counter like the following (test program):

let "n=0"
while [ $n -le 15 ]
do
printf "%s\r" "$n of xxxx bla bla..." # \r = carriage return
sleep 1
done

echo # to print the final line


My terminal command is: $myscript.sh | tee -a record.txt

in order to have a record of the actions of the program.

My problem (I guess) is that "tee" is adding a LF to the CR, i.e. I get a new line for every cycle of the loop so the record.txt becomes far too big.
IF I redirect directly from printf with > I only get one line (the final line).

Is there a way to avoid the added LF?
 
Old 07-09-2014, 04:27 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,968

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
You are not getting any LF characters in that file, just the same sequence of characters that is sent to the terminal. If you run "hexdump -c record.txt" you will see that. You seem to be under the mistaken impression that the CR character will somehow rewind that file back to the start so that the next line of output will overwrite what is already there. It does not, as you have discovered.
 
Old 07-09-2014, 04:29 PM   #3
kentyler
Member
 
Registered: Dec 2008
Location: Cleveland Ohio
Distribution: CentOS
Posts: 235

Rep: Reputation: 36
Use this

| tr -d "\n"
 
Old 07-10-2014, 08:50 AM   #4
klaus-3140
LQ Newbie
 
Registered: Jul 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
I have now found, that you are right rknichols; the LF's are not in the text file.
It seems that the LF's are introduced by the display program, because, it turns out, that "cat" displays the file OK (i.e. with CR and no LF), while "gedit" gives too many lines (i.e. with both CR and LF).
LibreOffice Writer on the other hand displays the file in a third way, as one long line, i.e. without both CR and LF.

My problem is now if there is a way to make the text file independent of the display program.
 
  


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
Why doesn't tee $(tty) produce output on the current terminal? openSauce Linux - Newbie 12 01-18-2016 01:25 PM
[SOLVED] redirecting output of set -x xerox Linux - Newbie 7 03-21-2011 03:03 AM
redirecting ALL audio output apenguinet Linux - Hardware 4 01-19-2011 03:27 AM
A little help with redirecting output tybalt Linux - Newbie 1 08-04-2007 11:08 PM
redirecting output using > cmk77 Slackware 8 11-10-2006 03:08 AM


All times are GMT -5. The time now is 08:24 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