starting form the top of the file I need 1. to get the the value in the 3rd column (c1)a1 b1 c1 d1 a2 b2 c2 d2 a3 b3 c3 d3 a4 b4 c4 d4
2. search in a second file (file_B.txt, not tab delimited and quite messy) all the matches for it.
3. when a match is found, I would like to append to the current value (c1), the value of 4th column (d1) in file_A.txt, separated by a space.
4. go back to the first file (file_A.txt), get the the value in the 3rd column in the second row (c2) and do another round of search and insert the value of d2 in the second file (file_B.txt).
5. go ahead with the search and replace until the end of file_A.txt is reached. I am an absolute newbee and I put together this code that does not work very well.
1. I don`t know how to tell perl to loop until the end of file_A.txt, so I have just used a for statement#!/usr/bin/perl open (datafile, "file_A.txt"); @fileinput = split("\t", <datafile>); for ($i = 2; $i <=200;){ open(OF, "file_B.txt"); #file_B.txt contains the original file open(NF, ">file_B_out.txt"); #file_B_out.txt contains the processe +d output while ($line = <OF>) { print "$fileinput[$i]\n"; print "$i\n"; $line =~ s/$fileinput[$i]/$fileinput[$i+1]/g; #print $line; print NF $line; } $i=$i+4; } close(NF); close(OF);
2. the search and replace routine does not work and I don`t understand why
Any suggestions and possibly example would be really appreciated
thanks.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |