I'm trying to find all lines of a file not being after a specific pattern.
For some time I had an issue with my
history using GNU
bash (version 4 and 5) where commands appeared in duplicates. I assumed this was due to the fact that in my
.bashrc I had the following line:
PROMPT_COMMAND="history -a; history -n; $PROMPT_COMMAND"
and since I'm using terminal multiplexers (
tmux) the above mentioned command gets executed several times (therefore
echo $PROMPT_COMMAND results in
history -a; history -n; history -a; history -n;
In some situations (especially when doing stuff concomitantly on different panes/windows/frames/buffers) the last command I entered was stored twice or even more often in my
~/.bash_history. This led to entries like the following:
#1596110297 yadm list -a | xargs -t ls -l yadm list -a | xargs -t ls -l
Needless to say, this is pretty annoying.
I just (hopefully) found a fix for the correction: this did NOT solve the issue with duplicated entries in the
history-issue (by changing the command to
PROMPT_COMMAND="history -a; history -n) but
Now I'd like to get rid of the duplicated entries.
Therefore I'm currently trying to find a regular expression to mark everything except lines starting with
# and one line after that. My first idea was to combine
grep -v (to invert the selection) and
grep -A 1 (to get additionally one line after the matching pattern). But
grep -v "^#" -A 1 ~/.bash_history
did not yield the result I hoped for.
Therefore my question: does anyone have a good idea on how to do that using
grep? If not: how could I accomplish this with other tools (