Link to home
Start Free TrialLog in
Avatar of omcr
omcr

asked on

regex to remove strange character from text file

Each line of text in log file I get from a device has a small rectangle at the begining, how do I get rid of it? Here is what it looks like, just imagine the zero's are small rectangles:

0SeqNum: 57
0Display: 1
0Point: 9
0CurrentState: Alarm

I have chomped, choped, tried to strip out with regexs, and have had no success.
Avatar of ozo
ozo
Flag of United States of America image

what do you see if you do
while( <> ){
  s/([^\n -z])/sprintf'\x%02x',ord $1/eg;
  print;
}
Avatar of omcr
omcr

ASKER

That gave me this:
\x0dSeqNum: 81\x0d
\x0dDisplay: 1\x0d
\x0dPoint: 9\x0d
\x0dCurrentState: Alarm\x0d
"\0xd" is a carriage return, was the log file generated in DOS?
perl -i.bak -pe 's/\xd//g' logfile
Avatar of omcr

ASKER

generated in unix.
Can you put "perl -i.bak -pe 's/\xd//g' logfile" into a file format instead of command line?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you dump the file so we can identify the strange character?
od -s logfile
od -x logfile

If you are on unix, thr tr utility may be simpler. The first example removes all control characters. The second, all characters with octal value of 015

cat logfile | tr -d '[:control:]' > new_logfile
cat logfile | tr -d '\015' > new_logfile
Avatar of omcr

ASKER

That did it. Thanks.
Avatar of omcr

ASKER

Did not see your post before I commented last time teraplane, but ozo's suggestion cleaned it up, and my scripts are now working. Thanks.