user3995867
user3995867

Reputation:

Deleting duplicate in a file without creating new file bash

I've been looking around here on how to delete duplicates in a file with preserving the order of the file. However, I couldn't find a command that deletes in place and not have to create a new file.

example

sample.txt

one
two
three
one
four
one
five

after deleting duplicates

sample.txt

one
two
three
four
five

Upvotes: 0

Views: 49

Answers (1)

Jetchisel
Jetchisel

Reputation: 7791

GNU awk has the inplace option.

gawk -i inplace '!seen[$0]++' file.txt 

Upvotes: 1

Related Questions