问题
I need to print all years greater than 1900 in a field. I have used to awk to get the field with the date. But I can not figure out how to use awk to pull only the years that are >=1900.
So far I pulled this field by entering this:
awk -F',' '{print $5}' presidents.csv
this gives me these dates
4/03/1893
4/03/1897
14/9/1901
4/3/1909
4/03/1913
4/03/1921
2/8/1923
4/03/1929
4/03/1933
12/4/1945
20/01/1953
20/01/1961
22/11/1963
20/1/1969
9/8/1974
20/01/1977
20/01/1981
20/01/1989
20/01/1993
20/01/2001
20/01/2009
Incumbent
回答1:
awk -F',' '{print $5}' presidents.csv | awk -F '/' '$3 > 1900 { print $1"/"$2"/"$3 }'
回答2:
Try this
#instead of presidents.csv
echo "
f1,f2,f3,f4,4/03/1893
f1,f2,f3,f4,4/03/1897
f1,f2,f3,f4,14/9/1901
f1,f2,f3,f4,4/3/1909
f1,f2,f3,f4,4/03/1913
f1,f2,f3,f4,4/03/1921" \
| awk -F',' '{print $5}' \
| awk '{split($0,lineArr,"/");if (lineArr[3] > 1900) print $0}'
14/9/1901
4/3/1909
4/03/1913
4/03/1921
来源:https://stackoverflow.com/questions/28388908/how-to-extract-year-from-date-format-and-find-all-years-greater-than