get rid of special characters

Hi Friends,

we have recently installed RHEL4.4 and when i give the commd
ls -l > tt it prints the file name with some special charactes like
^[[00m1 in the begining of the file name and at the end of the file name. I wanted to use the file names of removing it before taking
the backup and to use in awk script I want to remove the unprintable
characters .
I have tried
sed 's/^[...../p' input file > output file , but the characters varies in their
lenght so unable to remove . kindly guide ..

Thanks in advance for help.
:confused:

Sample input - what you are seeing
Sample output - your desired end-result
help in solving many problems.

That is especially true here since one prefix does not allow for the undertanding of a pattern.

It's real DATA ANALYSIS!

Why are you using "ls -l" if all you want is the names? Try ls -1.. That will simplify things for you... As for the special characters, get used to "od" Octal Dump.... Look at the hex values... try

ls -1 | od -cx > somefile

Then you can actually see what values are in those "unprintable" columns. Impossible to tell from what you write here because every character set interprets those values differently.... Once you know what the characters really are (in hex) you can come up with a way of eliminating them... Still, I don't know what RHEL is... Is it real unix?

1 Like

RHEL is Red Hat Enterprise (mumble) something, i.e. Linux.

Maybe it's as simple as "unalias ls". Some distros provide an alias which enables directory coloring, which will output some escape codes to provide text in different colors. If your terminal doesn't understand those escape codes, you would see something like what you describe.

Escape codes... Colors...

Yes makes sense. Hadn't thought of that. I've got a little project of my own that requires getting rid of escapes like that (simple perl pattern). I wondered what they might be for, now I remember... thanks

$INPTBffr =~ s/[^\x0A\x0D\x20-\x7E]+//g;

Using something like the above to strip binaries, and newlines leaving pure text stream.....