Clean console output routed to a file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Clean console output routed to a file
# 1  
Old 08-16-2011
Clean console output routed to a file

A friend routed some console output to a file for me. The problem is he used backspace and escape sequences all over the place. Using vi to view the file makes it difficult to read. Is there a program that will process the backspaces and remove the escape sequences?

e.g.,
Code:
bash-3.00$ pwd^[[K^H^H^Hcd ~
would be cleaned to be
bash-3.00$ cd ~


Last edited by pludi; 08-16-2011 at 05:19 PM..
# 2  
Old 08-16-2011
What are these characters - really control chars and escape sequences or just ASCII representation of them?
# 3  
Old 08-16-2011
They are real.

---------- Post updated at 04:39 PM ---------- Previous update was at 12:40 PM ----------

The reason you see the ascii representation in my example is because that is what vi displays when it reads the control characters.
# 4  
Old 08-22-2011
These are various control characters depending upon, tab, space, CTRL C, ESC, CTRL Z, backspace and others depending upon shell you are using.

As per my experience, there isn't any program which will do it for you. You can't even do something like "Search and Replace" as we do with newline characters in vi, because of key sequences pressed.
You need to use your experience for that to analyze.

Similar type of problem exists when you use putty log feature with "All Session Output".
# 5  
Old 08-22-2011
Quote:
Originally Posted by psshah
You can't even do something like "Search and Replace" as we do with newline characters in vi, because of key sequences pressed.
Sorry, but i think it is indeed possible. Here is a possible solution in sed for the backspace key - other key sequences can be done similarily. (I assume "^H" [ONE character!] to be the backspace sequence here.)

Code:
:loop
/.^H/ {
       s/.^H//
       b loop
     }

save this to a file and issue:

Code:
sed -f /path/to/cmdfile /path/to/infile > /path/to/outfile

This sed-script looks for a line with a character followed by a backspace, removes both and loops until no backspace character can be found any more. This way sequences of backspaces are deleted along with the characters they were used to remove. For example:

Code:
abcd^H^He    <- input
abc^He       <- after one pass of the loop
abe          <- after second pass of the loop

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 6  
Old 08-24-2011
Thanks for correcting me.
But I will check by myself, and let you know. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print Error in Console and both Error & Output in Log file - UNIX

I am writing a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file. But i am facing the below error. #! /bin/sh errExit () { errMsg=`cat... (1 Reply)
Discussion started by: sarathy_a35
1 Replies

2. Shell Programming and Scripting

Redirect an output from a script to a file and display it at a console simultaneously

Hi, I'd like to redirect the STDOUT output from my script to a file and simultaneously display it at a console. I've tried this command: myscript.sh | tail -f However, it doesn't end after the script finishes running I've also tried this: myscript.sh | tee ~/results.txt But it writes... (3 Replies)
Discussion started by: wenclu
3 Replies

3. Shell Programming and Scripting

[Shell/Perl(?)] Prepending timestamps to console output & writing results to a file

I do a lot of TSM work and I embarked on what I thought would be an easy task, and I'd be very happy for any input to save the pounding my keyboard is receiving :] By default, the output of TSM's console has no timestamping, making it hard to sort through accurately. This puts my console into... (5 Replies)
Discussion started by: Vryali
5 Replies

4. Shell Programming and Scripting

How to redirect the output of a cvs command to a file as well as the console.

Hi can anyone tell me how to redirect the ouput of a cvs command to a file as well as the console? i tried using cvs add <filename> | tee logFile cvs add <filename> 2>logFile 2>&1 All i could get is only on console or on file. Please help Thanks (2 Replies)
Discussion started by: ankitag2010
2 Replies

5. Shell Programming and Scripting

Redirecting output to both console and to a file

Hi All, Is there a way in Bash we can redirection some output to both console and the file at the same time. ~Parag (2 Replies)
Discussion started by: paragkalra
2 Replies

6. UNIX for Dummies Questions & Answers

Outbound file will be routed to new server

Hi, ---------- Post updated at 04:12 AM ---------- Previous update was at 04:09 AM ---------- This is the scripts.. Date=`date +"%m/%d/%y %H:%M:%S "` echo "Run on $Date" echo "Run on $Date" >&2 # Setting Variables PassDir=$PS_HOME/autosys/pass # Location of the... (0 Replies)
Discussion started by: sonja
0 Replies

7. AIX

All output at console and in a file at same time ?

I have several backup scripts I am improving which involves mksysb, savevg and tar. Is there a way to have the output of any command sent to the standard output as usual (terminal) and at the same time, send a copy of it all into a file ? Normal outputs and error outputs. Even if I am... (1 Reply)
Discussion started by: Browser_ice
1 Replies

8. UNIX for Dummies Questions & Answers

routing kill output from console to file

Hi , I am using the following command kill -3 pid ----which will return the thread dump. I want redirect this to file. I tried like the following two ways. kill -3 9843 >> srini.log kill -3 9852 >> srini 2>&1 But those two cases are failed :mad: pls let me knwo is there any... (2 Replies)
Discussion started by: srinivsa
2 Replies

9. Shell Programming and Scripting

Bourne Shell: Clean Display of stored procedure's output

Environment: Sun UNIX Language: Bourne Shell I have the following script and it works fine. Unfortunately, from user's perspective, it looks very messy because the user is able to see the output of the process caused by the print command. Is there a better way to overcome it? Here's the... (10 Replies)
Discussion started by: totziens
10 Replies

10. UNIX for Dummies Questions & Answers

Disable routed daemon at boot time????

I'm new to UNIX.... I'm running SCO UNIX and would like to disable routed daemon from being start at boot time. How should I do this????? Please help. (2 Replies)
Discussion started by: rrivas
2 Replies
Login or Register to Ask a Question