How to remove '^[[00m' in bash file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove '^[[00m' in bash file?
# 1  
Old 08-09-2012
How to remove '^[[00m' in bash file?

Hi,

This should be a simple one: I run the following commands in bash and ksh respectively but got differenant results:
Code:
# ls -l /var/log > /tmp/a
# vi /tmp/a

In bash shell, I got:
Code:
^[[00mtotal 827364
-rw-r----- 1 root root            189 Aug  9 00:00 ^[[00macpid^[[00m
-rw-r----- 1 root root            132 Aug  9 00:00 ^[[00;31macpid.1.gz^[[00m
-rw-r----- 1 root root            224 Jul 10 00:00 ^[[00macpid.2^[[00m

In ksh, I got:
Code:
total 828552
-rw-r----- 1 root root            189 Aug  9 00:00 acpid
-rw-r----- 1 root root            132 Aug  9 00:00 acpid.1.gz
-rw-r----- 1 root root            224 Jul 10 00:00 acpid.2

How can I remove those "^[[00m" got in bash?

Thank you!

Last edited by Franklin52; 08-10-2012 at 04:41 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 08-09-2012
Better to just not make them in the first place. ls --color=never

ls ought to be intelligent enough to tell when it's not writing to a terminal and avoid escape sequences, unless someone forced it always-on through an option or environment var.

Last edited by Corona688; 08-09-2012 at 01:57 PM..
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-09-2012
Issue solved! Thanks sent!!
# 4  
Old 08-09-2012
I don't think BASH had anything to do with it incidentally, except in that it would load a different profile than ksh does. Perhaps something in that profile forced color always-on.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 08-09-2012
Ok. I am going to check out the bash profiles. Thank you again!
# 6  
Old 08-09-2012
it should be in .bashrc, and it should be alias ls='ls --color=auto', which should avoid printing out color codes to non-terminals.
This User Gave Thanks to neutronscott For This Post:
# 7  
Old 08-09-2012
It may also be in the LS_COLORS environment variable.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash to remove find and remove specific extension

The bash below executes and does find all the .bam files in each R_2019 folder. However set -x shows that the .bam extension only gets removed from one .bam file in each folder (appears to be the last in each). Why is it not removing the extension from each (this is $SAMPLE)? Thank you :). set... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Scan and remove if file infected using bash

The below bash runs clamav on all files in DIR and produces virus-scan.log. My question is the portion in bold is supposed to move the infected files, lines not OK, to /home/cmccabe/quarantine. Does the bash look correct? Thank you :). virus-scan.log Mon Jan 16 14:39:05 CST 2017... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

Remove original file from directory after bash executes

The below bash works great, except I can not seem to delete the original file $f from the directory. Thank you :) For example, after the bash executes there are 8 files in the directory: 123.txt (original file) 123_remove.txt 123_index.txt 123_final.txt 456.txt (original file)... (11 Replies)
Discussion started by: cmccabe
11 Replies

4. Shell Programming and Scripting

bash - remove duplicates

I need to use a bash script to remove duplicate files from a download list, but I cannot use uniq because the urls are different. I need to go from this: http://***/fae78fe/file1.wmv http://***/39du7si/file1.wmv http://***/d8el2hd/file2.wmv http://***/h893js3/file2.wmv to this: ... (2 Replies)
Discussion started by: locoroco
2 Replies

5. Shell Programming and Scripting

How to remove comments from a bash script?

I would like to remove comments from a bash script. In addition, I would like to remove lines that consist of only white spaces, and to remove blank lines. #!/bin/bash perl -pe 's/ *#.*$//g' $1 | grep -v ^]*$ | perl -pe 's/ +/ /g' > $2 # # $1 INFILE # $2 OUTFILE The above code... (10 Replies)
Discussion started by: LessNux
10 Replies

6. Shell Programming and Scripting

Bash: How to remove the last character of a string?

In bash, how can one remove the last character of a string? In perl, the chop function would remove the last character. However, I do not know how to do the same job in bash. Many thanks in advance. (12 Replies)
Discussion started by: LessNux
12 Replies

7. Shell Programming and Scripting

remove ] followed by newline in bash

I need to remove ] followed by newline character to convert lines like: line1] line2 into: line1line2 (4 Replies)
Discussion started by: locoroco
4 Replies

8. Shell Programming and Scripting

How to get rid of cannot remove file error in bash script?

Hi Guys, I am creating a couple of temp. files in a script. After completing the script, I am using the rm command to delete these files. The files are getting deleted but I am getting "filename - cannot find file;no such file or directory" error in my bash shell terminal window. I am using... (3 Replies)
Discussion started by: npatwardhan
3 Replies

9. Shell Programming and Scripting

how can i remove comments in random positions in a file?(bash)

Suppose i have a file like this: #bla bla #bla bla bla bla bla Bla BLA BLA BLA #bla bla .... .... how can i remove all comments from every line,even if they are behind commands or strngs that are not comments? any idea how i could do that using awk? (2 Replies)
Discussion started by: bashuser2
2 Replies

10. Shell Programming and Scripting

Remove html tags with bash

Hello, is there a way to go through a file and remove certain html tags with bash? If it needs sed or awk, that'll do too. The reason why I want this is, because I have a monitor script which generates a logfile in HTML and every time it generates a logfile, the tags are reproduced. The tags... (4 Replies)
Discussion started by: dejavu88
4 Replies
Login or Register to Ask a Question