Tag Info

New answers tagged


Found a nice Perl one-liner for that, using md5 hashes ;), but this is slow and only worth it if you have very long lines and a huge file where it will greatly reduce memory use: perl -MDigest::MD5 -ne '$seen{Digest::MD5::md5($_)}++ or print' foo Therefore simply use perl -ne '$seen{$_}++ or print' foo Source Example cat foo foo fii foo bar foobar ...


There are multiple ways to do this. If ordering is not important then, sort and uniq are easiest to remember. However if you want to maintain ordering of the text file yet delete duplicates then awk does the trick. You can also use sed I believe. Here is an example /tmp/debugSys>cat fileWithDupText.txt line2 line21 line2 line1 line2 ...


Using awk awk '!x[$0]++' infile.txt > outfile.txt the way it works is that it keeps count of the lines in an array, and if the current count is zero, ie the first occurance, it prints the line, otherwise it continues to the next one.


KISS! (keep it simple ...) How about archiving this file with password (ZIP, 7Z, arj etc...), and allow users to work only with changeable part? See: [header.txt] A B C by Gero [contents.txt] whatever users want to change or have rights to change On printing or on producing final document: cat header.txt contents.txt To protect your precious ...


You can to some extent with chattr. Run the command sudo chattr +a file See man chattr for details. Note: root (or anyone with sudo/root access) can change the file back. You can restrict root to ro access with apparmor, and in that event you would have to have another user to append the file.


Using Gedit : Prerequisites: xclip, install from a terminal as sudo apt-get install xclip Gedit plugin External Tools. The goal of this plugin is to allow users to execute external commands from gedit interface. To install the plugin, open gedit go to Edit -> Preferences -> Plugins -> External Tools. Setup: To configure the plugin, go to Tools -> ...


With gVim, select the text, type :! and the command you want. The selected lines will be replaced by the output of the command. An example: Editing /etc/apt/sources.list: Selected the text and pressed :! (the '<,'> in the command line is automatically added), with command awk '{print $3}': The text was replaced with the output: Of course, Vim's ...

Top 50 recent answers are included