||11-17-2015 11:09 AM
sed or HISTTIMEFORMAT
Originally Posted by kalpeer
...in history file a date is getting updated along with each command. Is it possible to remove all other data except command.
The HISTTIMEFORMAT environment variable is what is causing the timestamps to be set in your history file. You could unset that variable and it will no longer be put in the history. There may be other times when you want or need the timestamps, so this might not be the best option.
Alternatively, you could use sed to read the history, discard the timestamps, and save it to a new file.
sed -n '/^#/ !p' /home/user/.bash_history > newfile
The -n option will prevent sed from copying out the active buffer. Without this you would see the the timestamps once and then each command line would repeated in the output. The next part matches lines that begin with a hash. The exclamation point reverses the match, and the p tells sed to print the matching lines. We get our input from the bash history file and redirect output of the command to newfile.
Using sed will keep the timestamps in your history file, which may be useful for other things you may want to do later, but allows you to get only the info that you want to use now.