Extract history from Korn shell

Posted by Luc on Stack Overflow See other posts from Stack Overflow or by Luc
Published on 2009-06-22T12:12:54Z Indexed on 2010/04/25 6:13 UTC
Read the original article Hit count: 268

Filed under:
|
|
|
|

I am not happy about the history file in binary format of the Korn shell.

I like to "collect" some of my command lines, many of them actually, and for a long time. I'm talking about years. That doesn't seem easy in Korn because the history file is not plain text so I can't edit it, and a lot of junk is piling up in it. By "junk" I mean lines that I don'twant to keep, like 'cat' or 'man'.

So I added these lines to my .profile:

fc -ln 1 9999 >> ~/khistory.txt

source ~/loghistory.sh > ~/khistory.txt

loghistory.sh contains a handful of sed and sort commands that gets rid of a lot of the junk. But apparently it is forbidden to run fc in the .profile file. I can't login whenever I do, the shell exits right away with signal 11. So I removed that 'fc -l' line from my .profile file and added it to the loghistory.sh script, but the shell still crashes.

I also tried this line in my .profile:

strings ~/.sh_history >> ~/khistory.txt

source ~/loghistory.sh

That doesn't crash, but the output is printed with an additional, random character in the beginning of many lines.

I can run 'fc -l' on the command line, but that's no good. I need to automate that. But how? How can I extract my ksh history as plain text?

TIA

© Stack Overflow or respective owner

Related posts about ksh

Related posts about shell