-1

File Mem.txt

[root@mavenir Sudhakar]# cat MEM.txt | awk '{print $4,$5}'

Output:

CARD_0-1 12
CARD_0-10 13
CARD_0-11 13
CARD_0-12 28
CARD_0-13 2
CARD_0-14 2
CARD_0-2 30
CARD_0-3 13
CARD_0-4 29
CARD_0-9 24
CARD_1-1 13
CARD_1-10 28
CARD_1-11 13
CARD_1-12 28
CARD_1-13 29
CARD_1-14 13
CARD_1-2 30
CARD_1-3 13
CARD_1-4 28
CARD_1-5 10
CARD_1-6 28
CARD_1-9 13

[root@mavenir Sudhakar]# cat cardnum.txt 
0-1
0-3
0-11
1-1
1-3
1-5
1-9
1-11
1-13

these are the two file where i need to select the value of the 2nd value from the MEM.txt file is the card num exist in cardnum.txt file.

the output should be like this

0-1  12
0-3  13
0-11  13
1-1  13
1-3  13
1-5  10
1-9  13
1-11  13
1-13  29
oguz ismail
  • 1
  • 16
  • 47
  • 69
  • possible duplicate of [How to merge two files using AWK?](http://stackoverflow.com/questions/5467690/how-to-merge-two-files-using-awk) – tripleee Aug 06 '14 at 08:03
  • You might want to read the help files and familiarize yourself with the site a little before posting your next question. This question could be a lot shorter and better stated, and you don't show any signs of having tried to solve it yourself. This tends to turn people off and will gather more downvotes than answers. – Tom Zych Aug 06 '14 at 10:08

1 Answers1

0

Here, now this should work.

#!/bin/bash
while lead line; do
    val=$(echo "$line" | awk -F _ '{print $2}');
    echo "$val";
done < mem.txt
cryptobionic
  • 69
  • 1
  • 7
  • This script is not working properly. this will print the entire 2nd line. but, i don't need the entire 2nd line as o/p i need only the numbers which present in cardnum.txt. – Sudhakar M Aug 08 '14 at 05:42
  • Haha see my part that says "doesn't work completely?" :) I was short on time then but I'll give it another shot now. – cryptobionic Aug 08 '14 at 14:21