compare data line by line from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare data line by line from a file
# 1  
Old 10-22-2008
compare data line by line from a file

Hi there

How can I compare data line by line from a file?

I need to compare the second value with the fourth to know if they are different.
If those values are different, I require to send my first value to the output until the complete file has been read.

This is my file:

0 FALSE 0.9402448762310354 TRUE
1 FALSE 0.9402448762310354 FALSE
2 FALSE 0.9402448762310354 FALSE
4 FALSE 0.9402448762310354 FALSE
10 FALSE 0.9402448762310354 FALSE
828 FALSE 0.9402448762310354 TRUE
829 FALSE 0.9402448762310354 TRUE
832 FALSE 0.9402448762310354 TRUE
833 FALSE 0.9402448762310354 TRUE
834 FALSE 0.9402448762310354 TRUE

Your help will be highly appreciated

Thanks

Lu
# 2  
Old 10-22-2008
Use nawk or /usr/xpg4/bin/awk on Solaris.


Code:
awk '$2!=$4&&$0=$1_' infile


Last edited by radoulov; 10-22-2008 at 06:27 PM.. Reason: corrected
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare two files line by line in bash

Hello All! Thanks for taking time out and helping. My issue is, I have two files that have file names in it. Now, i need to go through each line of both the files and when the file names are different, i need to rename the file. Below is the example: File1</ fil1ename1.txt filename2,txt... (2 Replies)
Discussion started by: svks1985
2 Replies

2. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

3. Shell Programming and Scripting

Compare fields in two files line by line

I am new to awk scripting. I want to do a field by word (field) comparison of two files File1.txt and File2.txt. The files contain a list of | (pipe) separated field. **File 1: ------------------- aaa|bbb|ccc|eee|fff lll|mmm|nnn|ooo|ppp rrr|sss|ttt|uuu|vvv** File 2: ... (7 Replies)
Discussion started by: dhruvmohan
7 Replies

4. Shell Programming and Scripting

Perl how to compare two pdf files line by line

Hi Experts, Would really appreciate if anyone can guide me how to compare two pdf files line by line and report the difference to another file. (3 Replies)
Discussion started by: prasanth_babu
3 Replies

5. Shell Programming and Scripting

how to compare file line by line with awk

im a newbee to unix. I have a requirement to compare two files with awk. file1.txt a b c d e file2.txt a b d e here i want to compare each line in file1 with corresponding line in file2 and prinf the line with difference. ie to check required result as shown below a=a (dont... (3 Replies)
Discussion started by: kiranps
3 Replies

6. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

7. Shell Programming and Scripting

Shell script to count number of ~ from each line and compare with next line

Hi, I have created one shell script in which it will count number of "~" tilda charactors from each line of the file.But the problem is that i need to count each line count individually, that means. if line one contains 14 "~"s and line two contains 15 "~"s then it should give an error msg.each... (3 Replies)
Discussion started by: Ganesh Khandare
3 Replies

8. Shell Programming and Scripting

Compare two text files line by line

Hi all I need help on comparing two texts files line by line and print the total number of lines matched. Any help is appreciated. Thanks in advance. (4 Replies)
Discussion started by: my_Perl
4 Replies

9. Shell Programming and Scripting

Formatting a text file to get data in exact line by line

I have my data something like this SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430693 07/01/2009 05:16:40 FR SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430746 07/01/2009 05:18:05 FR I want the output as follows.... (1 Reply)
Discussion started by: rdhanek
1 Replies

10. Shell Programming and Scripting

Compare multiple fields in file1 to file2 and print line and next line

Hello, I have two files that I need to compare and print out the line from file2 that has the first 6 fields matching the first 6 fields in file1. Complicating this are the following restrictions 1. file1 is only a few thousand lines at most and file2 is greater than 2 million 2. I need to... (7 Replies)
Discussion started by: gillesc_mac
7 Replies
Login or Register to Ask a Question