LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-19-2013, 02:46 AM   #1
Sudharshana
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Rep: Reputation: Disabled
Unhappy Weird strings in a text file: how to avoid/remove them?


I have a script generated file ,in my linux machine, which has got "<esc>"at the start of every line . It has also got "<esc>[36m>>><esc>[32m/main/1<esc>[m " like this at the end of every line. I am invonking the script that generates this file in my script. Now i need to remove all these occurences in this file from my ksh script. Please help me. absolutley clueless
 
Old 02-19-2013, 02:51 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
This is not urgent for us, please do not demand priority attention from a voluntary community. instead you should provide a useful and informative thread title that gives information about the query you have.
 
Old 02-19-2013, 02:54 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Try sed:
Code:
sed -e 's/\<esc\>//' infile.txt
Or using vi editor, in colon mode, invoke:
Code:
:%s/<esc>//g
If it do not help, then share a sample entry from infile.
 
Old 02-19-2013, 03:06 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
They seems color escape sequences. Any chance your script redirects the output of ls (maybe aliased as ls --color) to the file?
 
Old 02-19-2013, 03:09 AM   #5
Sudharshana
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
I need to make the changes in the same file. This ends up with an empty file after the script ends. I need these changes made to be reflected in the file. Its like, i need to open this file, make these replacements and then save the file. Can you please help me with this ?
 
Old 02-19-2013, 03:15 AM   #6
Sudharshana
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
I have no idea what they are. This file is generated by a perl script that i invoke in my shell script. Please let me know how to remove those instances
 
Old 02-19-2013, 03:27 AM   #7
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
Quote:
perl -pi -w -e "s/<esc>//g" <file_name>

perl -pi -w -e "s/<esc>\[36m>>><esc>\[32m\/main\/1esc>\[m//g" <file_name>
Both the commands will delete the patterns you have in the file.

Note: observe "\"(escape character) in the second command.
 
Old 02-19-2013, 03:28 AM   #8
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
<file_name> = script generated file
 
Old 02-19-2013, 03:29 AM   #9
Sudharshana
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
can i use these in my ksh script?
 
Old 02-19-2013, 03:32 AM   #10
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
Yes you can use them in you ksh, how ever you need to replace the <file_name> with the file_path.

---------- Post added 02-19-13 at 03:02 PM ----------

Try this as an example first!!
 
Old 02-19-2013, 03:37 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Sudharshana View Post
I have no idea what they are.
I would investigate that, instead. The best solution to remove something is to not generate it at all.
 
Old 02-19-2013, 03:48 AM   #12
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by RaviTezu View Post
perl -pi -w -e "s/<esc>\[36m>>><esc>\[32m\/main\/1esc>\[m//g" <file_name>
It's not so simple. The string shown in the sample (and only a sample) contain hidden control characters or some characters not in the ASCII charset:
Code:
[]<esc>[36m>>><esc>[32m/main/1[]<esc>[m
Sudharshana, please can you show a larger piece of the file (using CODE tags)?

Last edited by colucix; 02-19-2013 at 03:49 AM.
 
Old 02-19-2013, 03:58 AM   #13
Sudharshana
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
yes. what you say is absolutely true. Its like a hidden control char only. you can imagine, each of these lines starting with <esc> . I am unable to paste it as such.
/vobs/dsl/APME/ape/tp/TP_IsamTopLevelTest.nash
/cm2/auto/testcases/Design/ESAM/ETH/ETH_IPV6_PROTOCOLFILTER/ETH_IPV6_PROTOCOLFILTER_18.ars
/cm2/auto/testcases/Design/ESAM/ETH/ETH_IPV6_PROTOCOLFILTER/ETH_IPV6_PROTOCOLFILTER_19.ars
/cm2/auto/testcases/Design/ESAM/ETH/ETH_IPV6_PROTOCOLFILTER/ETH_IPV6_PROTOCOLFILTER_21.ars
/cm2/auto/testcases/Design/ESAM/ETH/ETH_VLANTUNNEL_TRAF_ROBUST/ETH_VLANTUNNEL_TRAF_ROBUST_01.ars
/cm2/auto/testcases/Design/FTTU/SRV/SRV_QOS_DS_SHAPER/SRV_QOS_DS_SHAPER_NGLT_COMMON_PROCS.tcl
/vobs/esam/build/fulltests/COMMON/ATCSuppress.txt
/vobs/esam/build/fulltests/COMMON/datafile.tcl
/vobs/esam/build/fulltests/COMMON/TraceCMDLT.txt

Please give me some idea to remove that <esc> sequence
 
  


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
[SOLVED] How can remove this weird chars from my text file? sopier Programming 4 12-21-2011 06:15 AM
suing sed to remove certain list of strings from a file ??? HuMan-BiEnG Linux - Distributions 11 10-13-2010 09:04 AM
[SOLVED] Script to remove text strings before a regexp on every other line? kmkocot Programming 10 07-12-2010 11:58 PM
Text file manipulation: alphanumeric strings CHARL0TTE Linux - Newbie 2 07-10-2009 09:40 AM
How to store text(strings) in a 2D character array reading from a text file(C++) bewidankit Programming 3 02-14-2008 07:08 AM

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

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