perl语言提取文本行或列
(2009-07-19 11:27:30)
标签:
perl提取行列杂谈 |
分类: perl语言学习 |
初学perl语言,看了好几章入门的书籍,最后感觉提取文本矩阵的某些行或者列还是比较有用的,下面是两个具体的命令,欢迎大家一起交流!
第一:提取含有某个关键字的行:
#!/usr/bin/perl
open FILE,
"E:/SNP.txt ";
open OUT1,'+>E:/file3.txt';
foreach
(<FILE>) {
@pairs=split(/ /, $_);
$count=@pairs;
if($pairs[$count-1] =~
m/^reference$/)
{
}
}
close(FILE);
close(OUT1);
第二:提取指定的某些列(提取1 2 3 5列):
#!/usr/bin/perl
open(INFILE,
"E:/file3.txt");
open(OUTFILE, ">E:/file4.txt")|| die "Cannot open
the newfile: $!\n";;
while
(<INFILE>) {
}
exit;
第三:去掉文本中有空行的命令:
#!/usr/bin/perl
open(INFILE,
"E:/file3.txt");
open(OUTFILE, ">E:/file4.txt")|| die "Cannot open
the newfile: $!\n";;
while
(<INFILE>) {
}
exit;
第四:自己编写的提取文本中含有某个关键字的命令(感觉比较实用):
#!/usr/bin/perl
open
FILE, "E:/chr_2.txt ";
open OUT1,'+>E:/chr_2_refference.txt';
foreach (<FILE>) {
if(/reference$/)
{
}
}
close(FILE);
close(OUT1);
第五:提取文本中非字符行的命令:
#!/usr/bin/perl
open(INFILE, "E:/最后得到的SNP/chr_X.txt");
open(OUTFILE, ">E:/去掉LOC以后得到的最后SNP/chr_X.txt")|| die
"Cannot open the newfile: $!\n";;
while (<INFILE>) {
}
exit;