Sponsored Content
Full Discussion: sort and compare files
Top Forums UNIX for Dummies Questions & Answers sort and compare files Post 302341449 by zaxxon on Thursday 6th of August 2009 03:10:58 AM
Old 08-06-2009
This is a bit abstract. To sort you use the command sort. For comparing you can use diff, comm, cmp, grep -f ..., awk, and maybe some more.
Unless you present us a concrete example of your 2 input files and the desired output I recommend to play around with those commands up there and/or use the advanced search function of this forum here since this is a question that came up relativ quite often.

When posting code, data or logs make sure you use CODE-tags, ty.

Last edited by zaxxon; 08-06-2009 at 04:18 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort and compare file

If I have 3 kinds of files in directory DATA1: FileA.20060315.dat, FileB.20060315.dat, FileC.20060315.dat FileC.20060316.dat FileA.20060317.dat, FileB.20060317.dat FileA.20060318.dat, FileB.20060318.dat, FileC.20060318.dat If 3 files have the same date then run $cat FileA.20060315.dat... (3 Replies)
Discussion started by: sabercats
3 Replies

2. Shell Programming and Scripting

Why do we use sort before compare ?

Dear All. Im trying to know how exactly the command "compare" works, does it compare line by line or field by field, and the most important thing is that why the files have to be sorted before we compare them? Thanks in advance (7 Replies)
Discussion started by: yahyaaa
7 Replies

3. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

4. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

5. Shell Programming and Scripting

comm command -- Sort and compare two files

Team, I have two files and I am trying to find the lines unique to file1. So i have executed the below command at shell prompt and got the correct results comm -23 <(sort test) <(sort test1) When i run the same command in Bash shell script, i got the correct results. But when i run... (5 Replies)
Discussion started by: forums123456
5 Replies

6. Shell Programming and Scripting

How to sort and compare files in more efficient manner?

Hello All, Iam using below method to sort and compare files. First iam doing sorting and changing the same file and then doing comparing and taking the final result to another file. sort -o temp.txt file1 mv temp.txt file1 sort -o temp.txt file2 mv temp.txt file2 sort -o temp.txt... (6 Replies)
Discussion started by: Vikram_Tanwar12
6 Replies

7. Shell Programming and Scripting

UNIX compare, sort lines and append difference

Hi, I have a file that needs to be converted: content is: a, b, 4 a ,b, 5 x, y, 1 a, b, 1 x, y, 3 how can i get: a, b, 1|4|5 x,y 1|3 (1 Reply)
Discussion started by: nike27
1 Replies

8. Shell Programming and Scripting

UNIX compare, sort lines and append difference

To make it easier, i gave following example. It is not homework or classwork. Instead, i have a huge csv file dump from tsql with 15 columns and around 300 rows. I was able to extract content that needs to be really converted. Here is the extract: ES FP,B1ES FP,70000,I,SL22,SL22 (70000) ES... (0 Replies)
Discussion started by: nike27
0 Replies

9. Shell Programming and Scripting

UNIX compare, sort lines and append difference

To make it easier, i gave following example. It is not homework or classwork. Instead, i have a huge csv file dump from tsql with 15 columns and around 300 rows. I was able to extract content that needs to be really converted. Here is the extract: ES FP,B1ES FP,70000,I,SL22,SL22 (70000) ES... (8 Replies)
Discussion started by: nike27
8 Replies

10. UNIX for Beginners Questions & Answers

Sort by record column, Compare with conditons and export the result

Hello, I am new to Unix and would like to seek a help, please. I have 2 files (file_1 and file_2), I need to perform the following actions. 1 ) Sort the both file by the column 26-36 (which is Invoice number) what is sort command with the column sort? 2) Compare the file_1.sorted and... (3 Replies)
Discussion started by: Usagi
3 Replies
SORT(3) 								 1								   SORT(3)

sort - Sort an array

SYNOPSIS
bool sort (array &$array, [int $sort_flags = SORT_REGULAR]) DESCRIPTION
This function sorts an array. Elements will be arranged from lowest to highest when this function has completed. PARAMETERS
o $array - The input array. o $sort_flags - The optional second parameter $sort_flags may be used to modify the sorting behavior using these values: Sorting type flags: o SORT_REGULAR - compare items normally (don't change types) o SORT_NUMERIC - compare items numerically o SORT_STRING - compare items as strings o SORT_LOCALE_STRING - compare items as strings, based on the current locale. It uses the locale, which can be changed using setlocale(3) o SORT_NATURAL - compare items as strings using "natural ordering" like natsort(3) o SORT_FLAG_CASE - can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively RETURN VALUES
Returns TRUE on success or FALSE on failure. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.4.0 | | | | | | | Added support for SORT_NATURAL and | | | SORT_FLAG_CASE as $sort_flags | | | | | 5.0.2 | | | | | | | Added SORT_LOCALE_STRING | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 sort(3) example <?php $fruits = array("lemon", "orange", "banana", "apple"); sort($fruits); foreach ($fruits as $key => $val) { echo "fruits[" . $key . "] = " . $val . " "; } ?> The above example will output: fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] = orange The fruits have been sorted in alphabetical order. Example #2 sort(3) example using case-insensitive natural ordering <?php $fruits = array( "Orange1", "orange2", "Orange3", "orange20" ); sort($fruits, SORT_NATURAL | SORT_FLAG_CASE); foreach ($fruits as $key => $val) { echo "fruits[" . $key . "] = " . $val . " "; } ?> The above example will output: fruits[0] = Orange1 fruits[1] = orange2 fruits[2] = Orange3 fruits[3] = orange20 The fruits have been sorted like natcasesort(3). NOTES
Note This function assigns new keys to the elements in $array. It will remove any existing keys that may have been assigned, rather than just reordering the keys. Note Like most PHP sorting functions, sort(3) uses an implementation of Quicksort. The pivot is chosen in the middle of the partition resulting in an optimal time for already sorted arrays. This is however an implementation detail you shouldn't rely on. Warning Be careful when sorting arrays with mixed types values because sort(3) can produce unpredictable results. SEE ALSO
asort(3), The comparison of array sorting functions. PHP Documentation Group SORT(3)
All times are GMT -4. The time now is 04:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy