Hi, Let's assume that I have a text list/file contains the following values: a b b c c d Code (markup): Now I want the output to have only: a d Code (markup): So, only the values those have occurred once. How I do that?
First you chose your language. Then, you use that language to do either a comparison by line, or put into array, or or or. PHP pseudocode would be something akin to read file, get contents, check if content matches next line, if it does, delete both, move along, if not, check next and so on. if you put this into an array, you can use array_unique() in PHP.
If you need it in PHP, it can be achieved using: // Array $array = array ('a', 'b', 'b', 'c', 'c', 'd'); // Count elements $array = array_count_values($array); // Get the elements that have a count of only 1 $array = array_keys(array_filter($array, create_function('$a','return $a == 1;'))); PHP:
Pseudo code that should fit most languages with minor fixes: (Since writing from my phone itll be a little mess and inaccurate) List<string> uniqueList = new List...; String[] fileContents = File.ReadFile(...); foreach(string line in fileContents) { if(uniqueList.Keys.Contains(line)) { uniqueList.Remove(line); } else { UniqueList.Add(line); } }
<?php $filename = 'file.txt'; // Open the file $fp = @fopen($filename, 'r'); // Add each line to an array if ($fp) { $array = explode("\n", fread($fp, filesize($filename))); print_r(array_unique($array)); } PHP: