2

I am using script command to record everything from terminal. But when I am opening the generated file its having lots of junk character. Can anyone help me to remove these junk characters from file or any other alternate way?

This file look like this:

ossvm10(0)> ls -lrt /usr/opt/temip/mmexe/mcc_fcl_pm.exe^M
^[[00m-rwxr-xr-x 1 root root 387517 Feb 18  2013 ^[[00;32m/usr/opt/temip/mmexe/mcc_fcl_pm.exe^[[00m^M
^[[m^[]0;temip@ossvm10:/home/dharmc^G[/home/dharmc]^M
ossvm10(0)> script -a unit_testing_TEMIPTFRLIN_00202_CR#9961.txtsum /usr/opt/temip/mmexe/mcc_fcl_pm.exe^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^[[1P^H^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^[[1P^H^G^G^G^G^G^G^G^G^M
06046   379^M
^[]0;temip@ossvm10:/home/dharmc^G[/home/dharmc]^M
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
dcds
  • 932
  • 4
  • 13
  • 23

1 Answers1

1

You can simply run:

dos2unix <filename>

This will remove all the ^M characters from the file. ^M is the carriage-return character generated in a DOS environment. The command dos2unix just converts the file from DOS to Unix format.

To remove the ^H and ^G characters, use sed:

sed -i 's/\^H//g;s/\^G//g' <filename>

Sreeraj
  • 4,984
  • 10
  • 38
  • 57
  • `dos2unix` will just clear out the ^Ms, it won't help with the ansi coding that got recorded. – Shadur Jan 20 '15 at 05:46
  • Thanks sree, but this has just removed the ^M characters. What about ^H,^G and some other junk characters? – dcds Jan 20 '15 at 05:47
  • @Dharmendra, updated the answer. Please take that as an example to remove junk characters other than ^H and ^G. – Sreeraj Jan 20 '15 at 06:32
  • ^H is backspace, won't removing them alter the semantics of the record? (i.e. `ha^Hi` is becomes `hai` when it should be `hi`) – Ulrich Schwarz Jan 20 '15 at 06:42
  • Yes, @Sree but still that is not working for "^[[m^[]0;" or "[1P". Anyway Thanks. – dcds Jan 20 '15 at 06:42