Pattern mapping


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern mapping
# 1  
Old 09-29-2010
Pattern mapping

Dear Friends,

Please help me on this
I have file A.txt containing text lines as below
HTML Code:
grectec; 30 ,50, 60, base_123 ; top09
grectec; 30 ,55, 60, base_123 ; top09  
grectec; 10 ,53, 60, base_123 ; top09
grectec; 50 ,57, 60, base_123 ; top09
...
...
another file B.txt containing test lines as below
HTML Code:
10 ken
30 jack
50 sack
60 mug
I need a script that check if the line containing text 30 add ken at the end of the line, similarly if the line containing 10 add ken at the end of the line.

output should be as: C.txt

grectec; 30 ,50, 60, base_123 ; top09 jack
grectec; 30 ,55, 60, base_123 ; top09 jack
grectec; 10 ,53, 60, base_123 ; top09 ken
grectec; 50 ,57, 60, base_123 ; top09 sack

I think its would be done using join command but dont know how:
# 2  
Old 09-29-2010
Code:
awk > C.txt 'NR == FNR {
  b[$1] = $2; next
  }
$0 = $0 FS b[$2]
  ' B.txt A.txt

This User Gave Thanks to radoulov For This Post:
# 3  
Old 09-29-2010
Quote:
Originally Posted by Danish Shakil
Dear Friends,

Please help me on this
I have file A.txt containing text lines as below
HTML Code:
grectec; 30 ,50, 60, base_123 ; top09
grectec; 30 ,55, 60, base_123 ; top09  
grectec; 10 ,53, 60, base_123 ; top09
grectec; 50 ,57, 60, base_123 ; top09
...
...
another file B.txt containing test lines as below
HTML Code:
10 ken
30 jack
50 sack
60 mug
I need a script that check if the line containing text 30 add ken at the end of the line, similarly if the line containing 10 add ken at the end of the line.

output should be as: C.txt

grectec; 30 ,50, 60, base_123 ; top09 jack
grectec; 30 ,55, 60, base_123 ; top09 jack
grectec; 10 ,53, 60, base_123 ; top09 ken
grectec; 50 ,57, 60, base_123 ; top09 sack

I think its would be done using join command but dont know how:
Below code works exactly as you want.but a.txt should be like
A.txt.
Code:
grectec; 10 ,53, 60, base_123 ; top09
grectec; 30 ,50, 60, base_123 ; top09
grectec; 30 ,55, 60, base_123 ; top09
grectec; 50 ,57, 60, base_123 ; top09

Code:
 
join -j1 2 -j2 1 a.txt b.txt

This User Gave Thanks to malikshahid85 For This Post:
# 4  
Old 09-30-2010
Question Multiple column mapping

Thanks Radoulov,

It worked, i need a little more help:

HTML Code:
File a.txt 
1    1     bash    enable   unlocked
1    4     kash    enable   locked
1    8     gash    enable   unlocked
2    1     bash    enable   unlocked
2    3     Lash    enable   unlocked 
2    7     Pash    enable   unlocked
HTML Code:
another File b.txt

1    1     jack
1    2     yack
1    4     back
1    8     sack
2    1     pack
2    3     fack
2    4     mack
2    7     lack
i need a third file c.txt on a mapping criteria of first two columns

1 1 jack bash enable unlocked
1 4 back kash enable locked
1 8 sack gash enable unlocked
2 1 pack bash enable unlocked
2 3 fack Lash enable unlocked
2 7 lack Pash enable unlocked
# 5  
Old 09-30-2010
Code:
awk 'NR == FNR {
  key[$1, $2] = $3; next
  }
$2 = $2 OFS key[$1, $2]
  ' OFS=\\t b.txt a.txt

This User Gave Thanks to radoulov 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

Many to many -- mapping

INPUT 13333--TEXT1 14444--TEXT2 13333--TEXT3 12233--TEXT5 14444--TEXT5 12233--TEXT1 12222--TEXT5 13333--TEXT09 what I'm looking for is something using awk arrays with below given output. 14444--TEXT2,TEXT5 13333--TEXT1,TEXT3,TEXT09 12233--TEXT5,TEXT1 12222--TEXT5 (6 Replies)
Discussion started by: busyboy
6 Replies

2. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

3. UNIX for Dummies Questions & Answers

Mapping drive

please forgive me. i know this is unix forum. CIFS can map to shared windows folder. i just wonder if windows can map to unix shared folder. if yes, please enlight me... (5 Replies)
Discussion started by: lawsongeek
5 Replies

4. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

5. UNIX for Advanced & Expert Users

Help With Mapping machine

Hi All, I need an urgent assistance please . My case below: I have a list of 500 IP addresses. All These ip addresses are mapped/connected to different machine kinds : NT, Linux, Switch, Router ,FW, and so on. My Requirement is to filter from all this ip address only the Linux... (0 Replies)
Discussion started by: James Stone
0 Replies

6. Shell Programming and Scripting

Creating unique mapping from multiple mapping

Hello, I do not know if this is the right title to use. I have a large dictionary database which has the following structure: where a b c d e are in English and p q r s t are in a target language., the two separated by the delimiter =. What I am looking for is a perl script which will take... (5 Replies)
Discussion started by: gimley
5 Replies

7. Shell Programming and Scripting

Need Help Mapping Arrays

I have the following arrays with different lengths that I want to map them with the same key. # Week numbers, 8 columns @headers = ("2011-34", "2011-35", "2011-36", "2011-37", "2011-38", "2011-39", "2011-40", "2011-41"); %data = ("2011-34", BCE, "2011-35", YZA, "2011-36",... (5 Replies)
Discussion started by: tqlam
5 Replies

8. UNIX for Dummies Questions & Answers

Mapping PF Keys in Vi

This is my first post and right off the bat, I want to let you know that my experience in UNIX is 2 days only backed up with over 20 years of IT working. So, if this is a dumb question or too stupid, please bear with me. I read somewhere on the web and also on these forums that you can map your... (7 Replies)
Discussion started by: sssccc
7 Replies

9. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

10. UNIX for Advanced & Expert Users

kernel mapping...

> how the sendmsg and recvmsg calls will know which kernel module to use (SCTP, RTP etc.) internally(kernel mapping: how kernel handle socket call) (1 Reply)
Discussion started by: prangin
1 Replies
Login or Register to Ask a Question