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 02-19-2013, 03: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, 03:51 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
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, 03: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, 04:06 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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, 04: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, 04: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, 04: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, 04: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, 04: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, 04: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, 04:37 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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, 04:48 AM   #12
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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 04:49 AM.
 
Old 02-19-2013, 04: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


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


All times are GMT -5. The time now is 01:47 PM.

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