Skip to main content
Added regex
Source Link
social
  • 325
  • 2
  • 7

Other ways to do this here as well:

   https://stackoverflow.com/questions/338285/prevent-duplicates-from-being-saved-in-bash-history/7449399#7449399

Excellent answer. If you would rather preserve the chronological order (instead of the input order) for your commands, modify dedup() by replacing awk '! x[$0]++' $@ with tac $@ | awk '! x[$0]++' | tac – trusktr

We can eliminate duplicate lines without sorting the file by using the awk command in the following syntax.

awk '!seen[$0]++' source.txt > target.txt 

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also in vim text editor nano using regex:

Press Ctrl + \ Enter your search string return Enter your replacement string return Press A to replace all instances

in :sort uvim :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 

Other ways to do this here as well:

 https://stackoverflow.com/questions/338285/prevent-duplicates-from-being-saved-in-bash-history/7449399#7449399

Excellent answer. If you would rather preserve the chronological order (instead of the input order) for your commands, modify dedup() by replacing awk '! x[$0]++' $@ with tac $@ | awk '! x[$0]++' | tac – trusktr

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also in vim text editor :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 

Other ways to do this here as well:  https://stackoverflow.com/questions/338285/prevent-duplicates-from-being-saved-in-bash-history/7449399#7449399

Excellent answer. If you would rather preserve the chronological order (instead of the input order) for your commands, modify dedup() by replacing awk '! x[$0]++' $@ with tac $@ | awk '! x[$0]++' | tac – trusktr

We can eliminate duplicate lines without sorting the file by using the awk command in the following syntax.

awk '!seen[$0]++' source.txt > target.txt 

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also in nano using regex:

Press Ctrl + \ Enter your search string return Enter your replacement string return Press A to replace all instances

in vim :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 
Added: preserving the order without sort
Source Link
social
  • 325
  • 2
  • 7

Other ways to do this here as well:

https://stackoverflow.com/questions/338285/prevent-duplicates-from-being-saved-in-bash-history/7449399#7449399

Excellent answer. If you would rather preserve the chronological order (instead of the input order) for your commands, modify dedup() by replacing awk '! x[$0]++' $@ with tac $@ | awk '! x[$0]++' | tac – trusktr

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also in vim text editor :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 

Other ways to do this here as well:

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also in vim text editor :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 

Other ways to do this here as well:

https://stackoverflow.com/questions/338285/prevent-duplicates-from-being-saved-in-bash-history/7449399#7449399

Excellent answer. If you would rather preserve the chronological order (instead of the input order) for your commands, modify dedup() by replacing awk '! x[$0]++' $@ with tac $@ | awk '! x[$0]++' | tac – trusktr

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also in vim text editor :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 
Removed `sort ~/.bash_history | uniq -u` as precluded by the OP in question
Source Link
social
  • 325
  • 2
  • 7

Other ways to do this here as well:

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also

sort ~/.bash_history | uniq -u

or in vim text editor :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 

Other ways to do this here as well:

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also

sort ~/.bash_history | uniq -u

or in vim text editor :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 

Other ways to do this here as well:

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also in vim text editor :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 
copy
Source Link
social
  • 325
  • 2
  • 7
Loading
sort & vim
Source Link
social
  • 325
  • 2
  • 7
Loading
Source Link
social
  • 325
  • 2
  • 7
Loading