我有一个如下的文本文件:
"Id","District Name","Neighborhood Name","Street","Weekday","Month","Day","Hour","Part of the day","Mild injuries","Serious injuries","Victims","Vehicles involved","Longitude","Latitude"
"2017S008429 ","Unknown","Unknown","Número 27 ","Friday","October",13,8,"Morning",2,0,2,2,2.12562442,41.34004482
"2017S007316 ","Unknown","Unknown","Número 3 Zona Franca / Número 50 Zona Franca ","Friday","September",1,13,"Morning",2,0,2,2,2.12045245,41.33942606
"2017S010210 ","Unknown","Unknown","Litoral (Besòs) ","Friday","December",8,21,"Afternoon",5,0,5,2,2.1673561,41.3608855
"2017S006364 ","Unknown","Unknown","Número 3 Zona Franca ","Friday","July",21,2,"Night",1,0,1,2,2.12452894,41.33766786
"2017S004615 ","Sant Martí","el Camp de l'Arpa del Clot","Las Navas de Tolosa ","Thursday","May",25,14,"Afternoon",1,0,1,3,2.185272,41.416365
"2017S007775 ","Sant Martí","el Camp de l'Arpa del Clot","Indústria / Trinxant ","Wednesday","September",20,12,"Morning",1,0,1,2,2.183245,41.416336
"2017S004484 ","Sant Martí","el Camp de l'Arpa del Clot","Trinxant / Indústria ","Saturday","May",20,21,"Afternoon",1,0,1,2,2.183245,41.416336
"2017S010680 ","Sant Martí","el Camp de l'Arpa del Clot","Indústria ","Tuesday","December",26,20,"Afternoon",2,0,2,1,2.183561,41.416372
"2017S005152 ","Sant Martí","el Camp de l'Arpa del Clot","Indústria ","Monday","June",12,15,"Afternoon",1,0,1,1,2.184059,41.416763
"2017S003932 ","Sant Martí","el Camp de l'Arpa del Clot","Maragall ","Wednesday","May",3,20,"Afternoon",1,0,1,1,2.181225,41.413958
"2017S010348 ","Sant Martí","el Camp de l'Arpa del Clot","Indústria ","Thursday","December",14,20,"Afternoon",1,0,1,2,2.18229,41.415772
"2017S000245 ","Sant Martí","el Camp de l'Arpa del Clot","ST ANTONI M CLARET / Pg Maragall ","Wednesday","January",11,7,"Morning",1,0,1,2,2.180453,41.41579
"2017S005695 ","Sant Martí","el Camp de l'Arpa del Clot","Sant Antoni Maria Claret / Guinardó ","Friday","June",30,12,"Morning",1,0,1,2,2.18114,41.416295
"2017S007384 ","Sant Martí","el Camp de l'Arpa del Clot","Sant Antoni Maria Claret ","Monday","September",4,16,"Afternoon",0,1,1,2,2.176324,41.412546
"2017S008080 ","Sant Martí","el Camp de l'Arpa del Clot","Sant Antoni Maria Claret ","Saturday","September",30,19,"Afternoon",1,0,1,2,2.176324,41.412546
"2017S003439 ","Sant Martí","el Camp de l'Arpa del Clot","Còrsega / Còrsega ","Monday","April",17,14,"Afternoon",1,0,1,2,2.178314,41.410784
"2017S002410 ","Sant Martí","el Camp de l'Arpa del Clot","CÒRSEGA / Dos de Maig ","Saturday","March",25,14,"Afternoon",4,0,4,2,2.177719,41.410323
"2017S009296 ","Sant Martí","el Camp de l'Arpa del Clot","Indústria ","Thursday","November",9,22,"Night",1,0,1,1,2.17674,41.411445
我尝试过类似的事情:
grep "May ,25" $1
用户输入的文件名在哪里$1
。基本上,它应该找到包含日期 5 月 25 日的行,但它什么也没显示。我知道确实有包含日期 5 月 25 日的行。
我也尝试了以下操作,但仍然不起作用:
grep "\"May\" ,25" $1
我究竟做错了什么?
答案1
引号也是字符 - 您的文件不包含May,25
,它包含"May",25
。所以
grep '"May",25' "$1"
或者
grep "\"May\",25" "$1"
(但不是 grep "\"May\" ,25" "$1"
- 空格也是字符)。
或者您可以使用能够理解 CSV 引用的 CSV 感知工具:
mlr --csv filter 'Month == "May" && Day == 25'
csvgrep -c Month -m May "$1" | csvgrep -c Day -m 25