LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Comparing fields in two lines (https://www.linuxquestions.org/questions/linux-newbie-8/comparing-fields-in-two-lines-4175463798/)

mathursiddarth 05-28-2013 01:35 PM

Comparing fields in two lines
 
I have two text files.

File 1:
Quote:

1000|25|ab|ed|45|50
1000|26|ed|ft|5|52
1000|27|dq|hb|35|54
1000|28|aw|ju|16|56
File 2:
Quote:

25|ab|ed|0|100|500|600|700
27|dq|hb|0|323|344|233|442
I need to compare the $2 field of file 1 to the $1 field of file 2 and append the $6 field of file 2 to file 1.
That is, i need the following output in my file 1:
Quote:

1000|25|ab|ed|45|50|500
1000|27|dq|hb|35|54|344
Have been scratching my head for too long now.
Any help? Thank you so much :)

TB0ne 05-28-2013 03:22 PM

Quote:

Originally Posted by mathursiddarth (Post 4960723)
I have two text files.
I need to compare the $2 field of file 1 to the $1 field of file 2 and append the $6 field of file 2 to file 1.
That is, i need the following output in my file 1:

Have been scratching my head for too long now.
Any help? Thank you so much :)

We'll be glad to help...post what you've written/tried so far. Otherwise, you could just read a line from file 1, grep for it in file 2, and (if it matches), and print out the results. You could assign each field to a variable for printing, use awk, or combinations of the two. There are lots of ways to do this.

David the H. 05-30-2013 01:52 PM

Why don't you try looking at some of the previous threads that have discussed the same general question? You can start with the ones in the Similar Threads box at the bottom of this page. ;)


All times are GMT -5. The time now is 12:18 PM.