find difference in file column...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find difference in file column...
# 1  
Old 04-15-2009
find difference in file column...

Hi All,

i have a file that is tab delimited. i need help to find the rows which are having same price based on the site code but some times, there are difference so i need to find only the records which are different in all site code.

Dept Sec Barcode 10001 10002 10003 10004
FMG Grocery 6271100040072 12.50 12.50 12.50 13.00
FMG Grocery 6271100041567 15.50 16.00 16.00 16.00
FMG Grocery 6271100041574 20.00 20.00 20.00 20.00
FMG Grocery 2000000159164 10.00 10.00 10.00 10.00
FMG Grocery 6271100041536 8.50 9.00 9.00 8.50

so above is the sample input and i need the output as below...

Dept Sec Barcode 10001 10002 10003 10004
FMG Grocery 6271100040072 12.50 12.50 12.50 13.00
FMG Grocery 6271100041567 15.50 16.00 16.00 16.00
FMG Grocery 6271100041536 8.50 9.00 9.00 8.50

Thanks,
# 2  
Old 04-15-2009
Code:
awk 'NR == 1 { print; next }
{ f = $4; for (i=5; i<=NF; i++) 
  if ($i != f) { print; break } 
  }' infile

With some grep implementations:

Code:
egrep  -v '(        [^      ]*)\1\1\1$' infile

The tab is entered ^V<TAB>

Last edited by radoulov; 04-15-2009 at 06:42 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk code to find difference in second file which is not present in first file .

Hi All, I want to find difference between two files and output only lines which are not present in second file .I am using awk and I am getting only the first difference but I want to get all the lines which are not present in file2 .Below is the code I am using . Please help to get the desired... (7 Replies)
Discussion started by: srinivasrao
7 Replies

2. UNIX for Beginners Questions & Answers

UNIX utility to find difference in folder, file and contents of file against a base version

Hi, I am trying to find out whether there are any Unix utilities that compares folders, files and contents within the file and provides a comprehensive report. The comparison can be against base version of a folder and file with content. Can you please let me know of such a utility? Thanks,... (6 Replies)
Discussion started by: Sripathi_ks
6 Replies

3. UNIX for Dummies Questions & Answers

Find the timestamp difference between two different colums in a file

Sample Input File 2014/10/09 CDE876172588765 00:09:45 00:10:10 200 200 11.7093 2014/10/09 CDE366134588757 01:04:34 01:04:54 210 210 9.8898 2014/10/09 CDE765172345745 03:05:46 03:06:01 100 100 10.0601 2014/10/09 ... (8 Replies)
Discussion started by: rpm120
8 Replies

4. Shell Programming and Scripting

I want to find the difference between two files, only for the header (column names)

Hi All, I want to find the difference between two files, by checking only the headers (column names) and report if any new column is added in the latest file. For Ex: If the file "declartion.txt has these columns url;image;id;showcase_id;showcase_name and the actual file "feed.txt" has... (34 Replies)
Discussion started by: Praveen Pandit
34 Replies

5. Shell Programming and Scripting

Difference between 2 files, one with 1 column and 2nd file with multiple columns

Hi, I need to find the difference between 2 files in unix and write the result in the new file File1: A B File2: X 123 hajkd Y 345 adjfka A 123 djafjhd B 678 dsndjks Output file: X 123 hajkd Y 345 adjfka Thanks. (6 Replies)
Discussion started by: nani1984
6 Replies

6. Shell Programming and Scripting

Difference of the same column when two other column matches and one column differs less than 1 hour

This is my input file : # cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9 This is the required output ... (1 Reply)
Discussion started by: Lakshmikumari
1 Replies

7. Homework & Coursework Questions

Script to find difference between 2 files by column

Hi , i am newbie to shell scripting and am trying to do the below job, A shell script to be run with a command like sh Compare.ksh file1.txt file2.txt 1 2 > file3.txt 1 2-are the key columns Consider the delimiter would be Tab or comma File 1: SK TEST NAME MATHS PHYSICS 21 1 AAA... (1 Reply)
Discussion started by: shakthi666
1 Replies

8. Shell Programming and Scripting

Script to find difference between 2 files by column

Hi , i am newbie to shell scripting and am trying to do the below job, A shell script to be run with a command like sh Compare.ksh file1.txt file2.txt 1 2 > file3.txt 1 2-are the key columns Consider the delimiter would be Tab or comma File 1: SK TEST NAME MATHS PHYSICS 21 1... (1 Reply)
Discussion started by: shakthi666
1 Replies

9. Shell Programming and Scripting

Calculate difference between consecutive data points in a column from a file

Hi, I have a file with one column data (sample below) and I am trying to write a shell script to calculate the difference between consecutive data valuse i.e Var = Ni -N(i-1) 0.3141 -3.6595 0.9171 5.2001 3.5331 3.7022 -6.1087 -5.1039 -9.8144 1.6516 -2.725 3.982 7.769 8.88 (5 Replies)
Discussion started by: malandisa
5 Replies

10. Shell Programming and Scripting

script to compare first column of two files and find difference

Hi, I want to write a script which will compare the 1st column of both the files and will give the difference. e.g:- my 1st file contains: 89 /usr 52 /usr/local 36 /tmp 92 /opt 96 /home 27 /etc/opt/EMCom 1 ... (3 Replies)
Discussion started by: adityam
3 Replies
Login or Register to Ask a Question