How to remove escape sequences from a text file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove escape sequences from a text file?
# 1  
Old 10-08-2015
How to remove escape sequences from a text file?

Hello friends,

Could anyone please advise on how to remove escape sequences from a text file?

Code:
$ file input.txt
input.txt:       ASCII English text, with escape sequences

I'm able to see those escape characters when opened in vi editor like shown below:

Code:
^[^[&l0O^[(s16.66h^[&a10L^[&l64F^[&l1S^[&a1G
TEST^[&a           73CPrint Date 25/09/15^[&a          105CPage      1
TRAVEL

but not when I run more command. That's how I want the file to be (by removing the escape seq - we also need to remove entire line if it has only escape sequences)

Code:
TEST 			Print Date 25/09/15 	                 Page 1
TRAVEL

Please advise,

many thanks in advance!!
# 2  
Old 10-08-2015
I currently have no file to test and not aware how to produce such but you can try this:
Code:
tr -d '[[:cntrl:]]' < infile > outfile

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 10-08-2015
Those are pcl5 escape sequences. Search pcl2txt.

---------- Post updated at 08:16 AM ---------- Previous update was at 07:25 AM ----------

If you want to write your own, the general rule is, delete all characters following an 'esc' (x027) until either a space or an upper case letter. The upper case letter should also be deleted, but not the space.
This User Gave Thanks to jgt For This Post:
# 4  
Old 10-08-2015
Thanks zaxxon for the reply Unfortunately it did not work and resulted a file with single line (vi shows 1 line) and wc -l shows 0.

Thanks jgt for your advice on pcl2txt but I couldn't get it for Linux. Could you please provide me a download link? Many thanks.
# 5  
Old 10-08-2015
Have a look at GhostPCL or GhostPDL. Both are part of Ghostscript.
# 6  
Old 10-08-2015
I don't think that there are any free versions.
Do you have the source code for the application that creates the file? Can you select a plain text printer? Can you run the report twice or does the report also update files?

Last edited by Don Cragun; 10-08-2015 at 10:41 PM.. Reason: Remove duplicated text.
# 7  
Old 10-13-2015
Code:
 ^[^[&l0O^[(s16.66h^[&a10L^[&l64F^[&l1S^[&a1G TEST^[&a           73CPrint Date 25/09/15^[&a          105CPage      1 TRAVEL

Whoever wrote the original program, has used the PCL5 escape sequence to centre the heading on the page. And not only that, the number of columns to tab is right justified in a 12 character field. If you do manage to remove the entire sequence, the fields in the heading will be separated by one character.
ie the '^[&a 73C' sequence is the complete PCL5 command, and it means tab 73 columns. Once all the PCL5 is removed, the line will look like:
Code:
TESTPrint Date 29/05/15Page 1

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove the text between all curly brackets from text file?

Hello experts, I have a text file with lot of curly brackets (both opening { & closing } ). I need to delete them alongwith the text between opening & closing brackets' pair. For ex: Input:- 59. Rh1 Qe4 {(Qf5-e4 Qd8-g8+ Kg6-f5 Qg8-h7+ Kf5-e5 Qh7-e7+ Ke5-f5 Qe7-d7+ Qe4-e6 Qd7-h7+ Qe6-g6... (6 Replies)
Discussion started by: prvnrk
6 Replies

2. Shell Programming and Scripting

Removing duplicate sequences and modifying a text file

Hi. I've tried several different programs to try and solve this problem, but none of them seem to have done exactly what I want (and I need the file in a very specific format). I have a large file of DNA sequences in a multifasta file like this, with around 15 000 genes: ... (2 Replies)
Discussion started by: 4galaxy7
2 Replies

3. Shell Programming and Scripting

Escape Sequences

Hi Gurus, Escape sequences \n, \t, \b, \t, \033(1m are not working. I just practiced these escape sequences. It worked first. Later its not working. Also the command - echo inside the script editor shows as shaded by a color. Before that echo inside the script editor wont show like this.... (4 Replies)
Discussion started by: GaneshAnanth
4 Replies

4. Shell Programming and Scripting

Mail utility not displaying escape sequences

Hello! I created a file that displays text underlined. However when I pass the file into the mail utility it doesnt display the underline. Here is the code: echo "\n\033 cat test_underline.txt mail -s "testing of underline" <email_address> < test_underline.txt Any ideas?... (8 Replies)
Discussion started by: DPERTS
8 Replies

5. UNIX for Dummies Questions & Answers

How to input escape sequences in Linux tty?

More details: Unicode, Framebuffer. I tried to press Esc and then what should follow, letters or brackets, but seems not to work. Probably i do something wrong. If somebody is familiar with escape sequences in the console, how do you do that? Thanks in advance. (4 Replies)
Discussion started by: Action
4 Replies

6. UNIX for Advanced & Expert Users

Remove escape characters from string

Hello all, I have a string var which contains formatting characters at the end, it is a string with EScape sequences at the end of it. How can I remove them so that I only keep the 'real' text? I tried : var1=${var1%%\033[0m} does not seem to do the job .... Please help Thanks (2 Replies)
Discussion started by: gio001
2 Replies

7. UNIX for Dummies Questions & Answers

Escape Sequences appearing in scripts

I hope this question isn't too vague... i recently switched from RedHat to Solaris 10, and found that the parts of a script that copy files between directories no longer work because escape sequences are appearing at the start and end of the filenames being read #!/usr/bin/bash cd... (1 Reply)
Discussion started by: jwm-wm
1 Replies

8. Solaris

Available escape sequences

:) Hi, Can any one help me to find available escape sequences in UNIX shell programming? ( Like \n, \c etc,. in C or C++) Iam generating one report using one of the script, in that it is very much essential. Regards, LOVE (6 Replies)
Discussion started by: Love
6 Replies
Login or Register to Ask a Question