AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Grep unique lines9/18/2023 ![]() :nno \d2 :g/^/kl\|if search('^'.escape(getline('.'),'\.*^$/').'$','bW')\|'ldįollowing uses a substitute to delete all repeated lines (leaving only the first line, while deleting following duplicate lines). not all the lines have similar content but they match on a specific field. Characters should be in quotation marks if they. last goes first and first goes last this is needed as sort -u will output the first entry as unique while using key-wise sort i.e. The grep filter finds a file for a specific character pattern and shows every line that includes that pattern. sort options: -n, -numeric-sort compare according to string numerical value -r, -reverse reverse the result of comparisons. uniq options: -c, -count prefix lines by the number of occurrences. 'cut' removes the first two characters added by 'diff', that are not part of the original content. ![]() For the opposite result one just has to replace '>' with '<'. This would print the entries in file2 which are not in file1. :nno \d1 :g/^/m0:g/^\(.*\)\n\_.*\%(^\1$\)/d:g/^/m0 tac will reverse the lines of input content i.e. The accepted answer is almost complete you might want to add an extra sort -nr at the end to sort the results with the lines that occur most often first. How about: diff file1 file2 grep '>' cut -c 3. (Use \zs for speed at beginning and end of the command maybe optional. There are two versions (and \v "verymagic" version as a variant of the second): the first leaves only the last line, the second leaves only the first line. If you need more control, here are some alternatives. ![]() ![]() The following command will sort all lines and remove duplicates (keeping unique lines): Here, the grep -F com.a file searches for a fixed com.a text in file (awk searches for a com.a substring on every line using the com.a regex, and index(0, 'com.a') version searches for com. ![]()
0 Comments
Read More
Leave a Reply. |