由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Usage of Grep???help!!!
相关主题
脚本问题求教perl: how to get the filename from the full path name
A problem on string parsing (using either grep or perl)perl monks: you should read "advanced perl programming"
请教一个perl的问题 (转载)perl script 求教 (Getopt::Long)
请教一个模式匹配问题how to print 2 exponential digits in windows by using Perl
Regular Expression 问题C++ 读不规则长度文件问题
问个关于正则表达式的超弱智问题...问一个python问题
还是awk牛B有人能解释一下这段C++代码吗
What language I should use?some problems with "cin"
相关话题的讨论汇总
话题: grep话题: usage话题: inputfile话题: outputfile话题: data
进入Programming版参与讨论
1 (共1页)
s*******f
发帖数: 757
1
I have data files with format like this:
year,mon,day,data.....
All are numbers and are seperated by coma. Can someone give me some suggestion
how I can use grep to extract the data at certain month, say, March-May.
I tried :
grep "^[[:digit:]\{\4\}[, ][3-5]]" inputfile >outputfile
It doesn't work.
Thanks!!!
a**n
发帖数: 313
2
awk -F, '{if($2==4 || $2==5) print}' inputfile > outputfile

【在 s*******f 的大作中提到】
: I have data files with format like this:
: year,mon,day,data.....
: All are numbers and are seperated by coma. Can someone give me some suggestion
: how I can use grep to extract the data at certain month, say, March-May.
: I tried :
: grep "^[[:digit:]\{\4\}[, ][3-5]]" inputfile >outputfile
: It doesn't work.
: Thanks!!!

c**t
发帖数: 2744
3
egrep "March|May" ..?

【在 s*******f 的大作中提到】
: I have data files with format like this:
: year,mon,day,data.....
: All are numbers and are seperated by coma. Can someone give me some suggestion
: how I can use grep to extract the data at certain month, say, March-May.
: I tried :
: grep "^[[:digit:]\{\4\}[, ][3-5]]" inputfile >outputfile
: It doesn't work.
: Thanks!!!

a**n
发帖数: 313
4
A perl solution:
#!/usr/bin/perl
# To run: perl test.pl inputfile
while(<>){
my @line = split(",",$_);
print $_ if($line[1]==3 || $line[1]==4 || $line[1]==5);
}

【在 s*******f 的大作中提到】
: I have data files with format like this:
: year,mon,day,data.....
: All are numbers and are seperated by coma. Can someone give me some suggestion
: how I can use grep to extract the data at certain month, say, March-May.
: I tried :
: grep "^[[:digit:]\{\4\}[, ][3-5]]" inputfile >outputfile
: It doesn't work.
: Thanks!!!

i**h
发帖数: 424
5
What do you mean it doesn't work? No match or too many matches?
1. Why do you need a space in [, ], the format does not imply that.
2. The outside bracket is not necessary.
3. And you don't need another "\" before "4".
Try
^[:digit:]\{4\},[3-5]

【在 s*******f 的大作中提到】
: I have data files with format like this:
: year,mon,day,data.....
: All are numbers and are seperated by coma. Can someone give me some suggestion
: how I can use grep to extract the data at certain month, say, March-May.
: I tried :
: grep "^[[:digit:]\{\4\}[, ][3-5]]" inputfile >outputfile
: It doesn't work.
: Thanks!!!

1 (共1页)
进入Programming版参与讨论
相关主题
some problems with "cin"Regular Expression 问题
help on string parse问个关于正则表达式的超弱智问题...
what's wrong with this scripts?variable passing?还是awk牛B
How to fix this? /bin/ls: Argument list too longWhat language I should use?
脚本问题求教perl: how to get the filename from the full path name
A problem on string parsing (using either grep or perl)perl monks: you should read "advanced perl programming"
请教一个perl的问题 (转载)perl script 求教 (Getopt::Long)
请教一个模式匹配问题how to print 2 exponential digits in windows by using Perl
相关话题的讨论汇总
话题: grep话题: usage话题: inputfile话题: outputfile话题: data