Compare Values in a Delimited Text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare Values in a Delimited Text file
# 1  
Old 08-29-2017
Compare Values in a Delimited Text file

Hi,

How do I compare two columns within a text file

If 2nd column values are same then I want to know 3rd column number matches or not

Example:

Code:
Prod  Stag1 1234.79
Prod  Stag2 1234.79 20
Prod  Stag3 1234.79 30
Prod  Stag4 1234.79
UAT  Stag1  1243.56
UAT  Stag2  1243.56 20
UAT  Stag3  1243.56 30
UAT  Stag4  1243.56

Expected Output

Code:
Prod & UAT are not matching for Stag1


Last edited by krux_rap; 08-29-2017 at 10:01 PM..
# 2  
Old 08-29-2017
Code:
awk '!($2 in f2) { f2[$2]=$3; f1[$2]=$1;next} f2[$1] != $3{ print f1[$2] " & " $1 " are not matching for " $2}' myFile

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 08-29-2017
Thanks vgersh. Updated the input data.
# 4  
Old 08-30-2017
Quote:
Originally Posted by krux_rap
Thanks vgersh. Updated the input data.
I don't get it. You give us a problem and vgersh99 gives you code that produces the output you requested.

Instead of telling us what is wrong with the code vgersh99 suggested, you add three more pairs of non-matching data to your sample input and expect the output to remain unchanged (thereby making sure that the code vgersh99 suggested no longer works).

Will you please provide a clear explanation as to what the code is really supposed to do so that we might have a chance of understanding why the three added non-matching pairs of input lines should not produce any output?
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete 'duplicated' column values and make a delimited file too?

Hi, I have the following output from an Oracle SQL statement and I want to remove duplicated column values. I know it is possible using Oracle analytical/statistical functions but unfortunately I don't know how to use any of those. So now, I've gone to PLAN B using awk/sed maybe or any... (5 Replies)
Discussion started by: newbie_01
5 Replies

2. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

3. UNIX for Dummies Questions & Answers

Sort tab delimited file according to which rows have missing values

Hello! I have a tab delimited file with values in three columns. Some values occur in all three columns, other values are present in only one or two columns. I would like to sort the file so that rows with no missing values come first, rows with one missing values come next, and rows with two... (9 Replies)
Discussion started by: MBarrett1213
9 Replies

4. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

5. UNIX for Dummies Questions & Answers

Extracting rows from a space delimited text file based on the values of a column

I have a space delimited text file. I want to extract rows where the third column has 0 as a value and write those rows into a new space delimited text file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

6. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

7. UNIX for Dummies Questions & Answers

Converting a text file with irregular spacing into a space delimited text file?

I have a text file with irregular spacing between values which makes it really difficult to manipulate. Is there an easy way to convert it into a space delimited text file so that all the spaces, double spaces, triple spaces, tabs between numbers are converted into spaces. The file looks like this:... (5 Replies)
Discussion started by: evelibertine
5 Replies

8. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 Replies

9. Shell Programming and Scripting

Retrieving values from tab-delimited file in unix script

Hi I am trying to retrieve values from a tab-delimited file.I am using while read record value=`echo $record | cut -f12` done Where 12 is the column no i want retieve and record is one line of the file. But it is returning the full record. Plz help (4 Replies)
Discussion started by: akashtcs
4 Replies

10. Shell Programming and Scripting

Compare 2 delimited file

Hi, Need one more help We have 2 file which we need to compare First file data.txt has data like 223300 440066 and second file ref.txt has 223300|abcd 223456|rtye 5423890|uytr 440066|uiyu I need to compare these 2 file and the output should be 223300|abcd 440066|uiyu (4 Replies)
Discussion started by: ashu_r2001
4 Replies
Login or Register to Ask a Question