LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 02: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, 03:27 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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, 03:29 PM   #3
kentyler
Member
 
Registered: Dec 2008
Location: Newark Ohio
Distribution: Fedora Core
Posts: 270

Rep: Reputation: 38
Use this

| tr -d "\n"
 
Old 07-10-2014, 07: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



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 12:25 PM
[SOLVED] redirecting output of set -x xerox Linux - Newbie 7 03-21-2011 02:03 AM
redirecting ALL audio output apenguinet Linux - Hardware 4 01-19-2011 02:27 AM
A little help with redirecting output tybalt Linux - Newbie 1 08-04-2007 10:08 PM
redirecting output using > cmk77 Slackware 8 11-10-2006 02:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:42 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
Open Source Consulting | Domain Registration