reading files and pasting in another text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading files and pasting in another text file
# 1  
Old 12-06-2011
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"
Code:
28434710
23456656
3456895

& finding this "event" in some other text file 2.txt, which has information in the following format
Code:
#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
Code:
160998:57:38130838
163302:57:28434710


Many Thanks in advance
pooja..
# 2  
Old 12-06-2011
Code:
while read line; do grep $line file2| awk '{printf("%s:%s:%s",$4,$8,$6)}'; done < file1

# 3  
Old 12-06-2011
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..
# 4  
Old 12-06-2011
Code:
 
nawk '{print $1}' 1.txt | while read line; do grep $line 2.txt| awk '{printf("%s:%s:%s",$4,$8,$6)}' >> 3.txt ; done

# 5  
Old 12-06-2011
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 Smilie Smilie
Code:
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:
Code:
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 Smilie Smilie
Code:
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:
Code:
166408:811:10220629
166841:1002:10331710

thanks
pooja.
# 6  
Old 12-06-2011
after the third %s use \n

Code:
 
"%s:%s:%s\n"

# 7  
Old 12-06-2011
Code:
nawk 'FNR==NR{f2[$6]=$4 OFS $NF OFS $6;next}$1 in f2 {print f2[$1]}' OFS=: file2.txt file1.txt > file3.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to write in other language in text/xml file by reading english text/xml file using C++?

Hello Team, I have 2 files.one contains english text and another contains Japanese. so i have to read english text and replace the text with Japanesh text in third file. Basically, I need a help to write japanese language in text/xml file.I heard wstring does this.Not sure how do i write... (2 Replies)
Discussion started by: SA_Palani
2 Replies

2. Shell Programming and Scripting

help with pasting files in filesystem

quick question.. say i have few files in D or E drive.. i want to paste them in Filesystem that is /home/vivek folder... but when i try to do that it shows some error saying "There is not enough space on the destination. Try to remove files to make space." but i think its due to authorization... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

Pasting files with different number of lines

Hi all, I tried to use the paste command to paste two files with different number of lines. e.g. file1 A 1 B 1 C 2 D 2 file2 A 2 B 3 C 4 D 4 E 4 (2 Replies)
Discussion started by: f_o_555
2 Replies

4. UNIX for Dummies Questions & Answers

Copying and Pasting columns from one text file to another

I have a tab delimited text file that I want to cut columns 3,4,5 from. Then I want to paste these columns into a space delimited text file between columns 2 and 3. I still want to keep the space delimited format in the final text file. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. UNIX for Dummies Questions & Answers

Pasting a column into a text file

I have two text files: One is a single column of numbers and the other is a space delimited text file with multiple columns. I want to paste the single column of numbers into the second column of the latter text file. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

pasting fields from two files into one

i have two files with contents file a 1234,abcf 2345,drft 4444,befr file b tom,3 sam,5 dog,7 i want to print first column of file b and join to file a and get output as below tom,1234,abcf sam,2345,drft dog,4444,befr (2 Replies)
Discussion started by: dealerso
2 Replies

7. Shell Programming and Scripting

pasting two files while transposing one of them

hey, I have more a structural problem. I have two input files: 1.inp: 1 2 3 a b c 2 3 4 d f g and the 2.inp 6 6 6 7 7 7 8 8 8 The goal is to get as much output files (with a name 1_2_3.dat) as lines in 1.inp are like this: 6 6 6 a 7 7 7 b 8 8 8 c (5 Replies)
Discussion started by: ergy1983
5 Replies

8. Programming

fopen() + reading in large text files

For reading in large text files (say files over 1kB in size) are there any issues with fopen() that I should be aware of ? cheers (2 Replies)
Discussion started by: JamesGoh
2 Replies

9. UNIX for Dummies Questions & Answers

Trouble pasting multiple files together!!

Hi, I would like to paste multiple files together into one large file. I have 23 of them and I would like to link them on a common variable without writing all the file names out (like in a simple join). Each has about 28,000 columns, but only 17 rows. So the final product would be a single file... (2 Replies)
Discussion started by: etownbetty
2 Replies

10. UNIX for Dummies Questions & Answers

pasting text into an existing file

I have a text file that has over 300 lines that I need to paste identical data to. What is the easiest way to do this? For example if I have a file that has lines of text xxxxxxxx and I would like to change each line to look like this "display text(xxxxxxxx)". What would be the easiest way to do... (3 Replies)
Discussion started by: darthur
3 Replies
Login or Register to Ask a Question