reading files and pasting in another text file

Hi all,
I have certain task to do, which involves reading the first column of 1.txt file.
This is variable "event"

28434710
23456656
3456895

& finding this "event" in some other text file 2.txt, which has information in the following format

#Zgamma:    1    run: 160998    event:    38130838      lumis:   57
#Zgamma:    2    run: 163302    event:    28434710      lumis:   57
#Zgamma:    3    run: 163286    event:   157864346      lumis:  380

When "event" variable is found in the 2.txt then finally filling this information in some third txt file 3.txt in the following format:run:lumi:event

160998:57:38130838
163302:57:28434710

Many Thanks in advance
pooja..

while read line; do grep $line file2| awk '{printf("%s:%s:%s",$4,$8,$6)}'; done < file1

Hi, thanks for replying..
but unfortunately it is not working...If you check the task again, i need to read EVENT variable information from 1.txt then grep some column information form 2.txt and finally paste back in 3.txt in the form of run:lumi:event

Many thanks
pooja..

 
nawk '{print $1}' 1.txt | while read line; do grep $line 2.txt| awk '{printf("%s:%s:%s",$4,$8,$6)}' >> 3.txt ; done

Hi again,
sorry sorry, yeah it is working...here is the output, in this format it would be difficult for me to make use of it :frowning: :frowning:

166408:811:1022062957166841:1002:1033171021166380:958:1049666825165415:941:1098155457165514:107:112318244165993:1041:1141388422166841:13:11422913165993:1059:115938128\
5165567:108:117811963166408:118:119002265161311:256:127049784163270:21:13051727165993:1241:1335231494166161:108:136130812166033:1030:1369299428166512:1216:13860152141\
65993:1341:1429403883163583:188:143564804166150:12:14454461166380:127:150338865166049:130:154766875166860:15:15695851165970:149:157415649166554:145:158243454166514:18\
4:158493968166049:133:159178029166380:135:159468360166033:127:162742652166512:1469:1629801420161311:335:164722295163255:24:16495923165993:1645:1702706516160957:324:17\
1464518165205:198:172105140163374:321:172451855165487:135:172956698166049:143:173913337161312:427:174269069166346:150:175762389161311:361:176660107166781:158:18121802\
5166512:1670:1814662583163300:348:186141156166565:22:18668742165415:176:188272342166781:166:191511128166512:1797:1927687957165415:183:197814055166462:205:201203662166\
486:54:20289670161310:44:21709224166438:193:219396037163760:325:223525450163659:306:233271522166554:205:237884234163334:416:239958340161311:535:254050277166565:30:259\
54407163588:40:25996134163297:46:26266123160957:490:263905272163587:38:26474760163069:506:279972714166781:238:280796212163588:43:28605492163334:502:288270305163757:38\
:28975302166514:341:291675700166699:277:292343190163758:424:302075539166784:319:307160579166787:338:307321197163630:91:30946729163659:435:324853709166699:311:33132908\
7166784:36:33476247163758:478:338908984165506:66:34222711166161:38:34354697165617:247:345261113163374:672:347507811166033:257:357600365166150:27:36158941161310:63:364\
65601166554:307:365271476163332:546:370703298161312:92:37613683166462:361:376811946166033:271:378318625166763:341:379689936166438:335:387301367166763:354:395306362165\
472:349:395638450165567:324:398979654163584:55:40060070166859:65:41591259163817:438:417094140165633:330:427570232163255:662:428865793166763:387:433029892163659:628:45\
4892473166859:68:45552475163340:91:46059998166565:523:475240596165364:382:477092177163255:750:480867793166859:409:484226899163402:84:48775405165567:398:49624778716541\
5:443:520823523166408:410:521096034165993:73:53444136166781:56:54111826166563:544:545379656161311:12:5508965163340:110:55757684165633:434:568552960166408:453:57774621\
7163588:85:57868564166701:663:597906708166033:430:604838755166565:674:606802385163332:109:61970235166033:442:621278747166408:506:645826356166763:581:648955292166763:5\
87:654800261166438:599:683013393165548:513:684231922166565:766:685379086166699:642:691823115165487:55:69199739166860:8:6962614166033:502:703260471165467:558:717286940\
163296:127:72023863165467:561:721540213165570:549:725481653166841:684:730246685165364:593:731328503165514:536:736326781166512:81:74316743166565:849:754865831166565:85\
7:761643131163817:830:762290553166408:609:775466243165415:666:775937547166699:732:778650988165567:81:78016074166462:102:78861050166486:107:79048093165993:93:791150201\
63402:128:80017493166033:579:807415575166380:742:825478701165993:739:830719222163817:929:847308694165467:693:885678072163297:153:88614414166033:646:894581201165993:82\
3:919526464165472:783:924298969165993:839:937105906166033:682:941679915163758:131:98288645

Will it be possible to get the information saved like:

166408:811:10220629
166841:1002:10331710

thanks
pooja.

---------- Post updated at 09:22 AM ---------- Previous update was at 09:22 AM ----------

Hi again,
sorry sorry, yeah it is working...here is the output, in this format it would be difficult for me to make use of it :frowning: :frowning:


166408:811:1022062957166841:1002:1033171021166380:958:1049666825165415:941:1098155457165514:107:112318244165993:1041:1141388422166841:13:11422913165993:1059:115938128\
5165567:108:117811963166408:118:119002265161311:256:127049784163270:21:13051727165993:1241:1335231494166161:108:136130812166033:1030:1369299428166512:1216:13860152141\
65993:1341:1429403883163583:188:143564804166150:12:14454461166380:127:150338865166049:130:154766875166860:15:15695851165970:149:157415649166554:145:158243454166514:18\
4:158493968166049:133:159178029166380:135:159468360166033:127:162742652166512:1469:1629801420161311:335:164722295163255:24:16495923165993:1645:1702706516160957:324:17\
1464518165205:198:172105140163374:321:172451855165487:135:172956698166049:143:173913337161312:427:174269069166346:150:175762389161311:361:176660107166781:158:18121802\
5166512:1670:1814662583163300:348:186141156166565:22:18668742165415:176:188272342166781:166:191511128166512:1797:1927687957165415:183:197814055166462:205:201203662166\
486:54:20289670161310:44:21709224166438:193:219396037163760:325:223525450163659:306:233271522166554:205:237884234163334:416:239958340161311:535:254050277166565:30:259\
54407163588:40:25996134163297:46:26266123160957:490:263905272163587:38:26474760163069:506:279972714166781:238:280796212163588:43:28605492163334:502:288270305163757:38\
:28975302166514:341:291675700166699:277:292343190163758:424:302075539166784:319:307160579166787:338:307321197163630:91:30946729163659:435:324853709166699:311:33132908\
7166784:36:33476247163758:478:338908984165506:66:34222711166161:38:34354697165617:247:345261113163374:672:347507811166033:257:357600365166150:27:36158941161310:63:364\
65601166554:307:365271476163332:546:370703298161312:92:37613683166462:361:376811946166033:271:378318625166763:341:379689936166438:335:387301367166763:354:395306362165\
472:349:395638450165567:324:398979654163584:55:40060070166859:65:41591259163817:438:417094140165633:330:427570232163255:662:428865793166763:387:433029892163659:628:45\
4892473166859:68:45552475163340:91:46059998166565:523:475240596165364:382:477092177163255:750:480867793166859:409:484226899163402:84:48775405165567:398:49624778716541\
5:443:520823523166408:410:521096034165993:73:53444136166781:56:54111826166563:544:545379656161311:12:5508965163340:110:55757684165633:434:568552960166408:453:57774621\
7163588:85:57868564166701:663:597906708166033:430:604838755166565:674:606802385163332:109:61970235166033:442:621278747166408:506:645826356166763:581:648955292166763:5\
87:654800261166438:599:683013393165548:513:684231922166565:766:685379086166699:642:691823115165487:55:69199739166860:8:6962614166033:502:703260471165467:558:717286940\
163296:127:72023863165467:561:721540213165570:549:725481653166841:684:730246685165364:593:731328503165514:536:736326781166512:81:74316743166565:849:754865831166565:85\
7:761643131163817:830:762290553166408:609:775466243165415:666:775937547166699:732:778650988165567:81:78016074166462:102:78861050166486:107:79048093165993:93:791150201\
63402:128:80017493166033:579:807415575166380:742:825478701165993:739:830719222163817:929:847308694165467:693:885678072163297:153:88614414166033:646:894581201165993:82\
3:919526464165472:783:924298969165993:839:937105906166033:682:941679915163758:131:98288645

Will it be possible to get the information saved like:

166408:811:10220629
166841:1002:10331710

thanks
pooja.

after the third %s use \n

 
"%s:%s:%s\n"
nawk 'FNR==NR{f2[$6]=$4 OFS $NF OFS $6;next}$1 in f2 {print f2[$1]}' OFS=: file2.txt file1.txt > file3.txt

Perfect..:slight_smile: :slight_smile:

thanks a lot
pooja..