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!!!
|
|