0

So I found this

https://unix.stackexchange.com/questions/171091/remove-lines-based-on-duplicates-within-one-column-without-sort

It does exactly what I'm looking for, but I need to edit the file in place without creating another file. I've checked the man page and sadly I can't really find a solution.

I've browsed the suggested similar questions and none of them specifically address what I'm trying to do.

I have tried awk -f',' '!seen[$4]++' ~/Desktop/info.csv > ~/Desktop/info.csv but when it overwrites, the file is completely blank.

TIA for any help.

Community
  • 1
  • 1
cducasse
  • 9
  • 5
  • 1
    If you have Gnu awk you may be able to [edit in place depending on your version](http://stackoverflow.com/questions/16529716/awk-save-modifications-inplace). The second answer on that question also suggests just `awk ... file && tmp && mv tmp file` which seems like it would work fine too. – JNevill Mar 09 '16 at 16:27
  • It's not possible to edit your file without creating another file unless you use `ed` for its internal buffer the same size as your input file or read the whole file into an array with `awk` or `perl` or similar or use an approach like that detailed at http://stackoverflow.com/a/17331179/1745001. If, on the other hand, you just want to avoid **naming** the tmp file then edit your question to state that. – Ed Morton Mar 09 '16 at 16:35
  • The `>` is executed by *the shell* and *before* awk starts. When `>` is used, the shell either creates or truncates the file to zero length. – hek2mgl Mar 09 '16 at 17:00

0 Answers0