计算文件中的国家/地区代码并保存文件命令或 bash 脚本

计算文件中的国家/地区代码并保存文件命令或 bash 脚本

情况: 我想编写 bash 脚本或命令,仅计算 /var/log/mywebsite.log 中的国家/地区代码,然后保存文件。我希望此脚本检查 Linux 时间并仅获取同一天的国家/地区值,每次启动此脚本时填充新值。我只想获取 11 月 26 日的值而不是 11 月 25 日,linux 日期是 11 月 26 日

所需输出:文件/home/mywebsite/www/countries.txt

IN:35
US:123
QA:5
RU:23
MA:23
etc.

/var/log/mywebsite.log

    123.223.129.225 - [25/Nov/2017:02:01:59 +1100] GET /pdf/aloha-micronutrients.html HTTP/1.1 US
    64.223.129.225 - [25/Nov/2017:02:01:59 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    53.223.129.225 - [25/Nov/2017:02:01:59 +1100] GET /dmcaemail.png HTTP/1.1 IN
    223.223.129.225 - [26/Nov/2017:02:01:59 +1100] GET /pdf/role-of-micronutrients.html HTTP/1.1 IN
    223.223.129.225 - [26/Nov/2017:02:01:59 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 IN
    223.223.129.225 - [26/Nov/2017:02:01:59 +1100] GET /dmcaemail.png HTTP/1.1 IN
    223.223.129.225 - [26/Nov/2017:02:01:59 +1100] GET /logo.jpg HTTP/1.1 IN
    66.249.92.158 - [26/Nov/2017:02:02:00 +1100] GET /pdf/role-of-micronutrients.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:02:07 +1100] GET /pdf/gastroscopy.html HTTP/1.1 US
    168.235.194.192 - [26/Nov/2017:02:02:08 +1100] GET /pdf/astringents.html HTTP/1.1 US
    168.235.194.192 - [26/Nov/2017:02:02:08 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    168.235.194.192 - [26/Nov/2017:02:02:08 +1100] GET /logo.jpg HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:02:18 +1100] GET /Why-study-literature--pdf.html HTTP/1.1 US
    40.77.167.11 - [26/Nov/2017:02:02:39 +1100] GET /index.php/about/ HTTP/1.1 US
    37.211.15.120 - [26/Nov/2017:02:02:41 +1100] GET /The-Honey-Bee--Florida-State-University--pdf.html HTTP/1.1 QA
    157.55.39.169 - [26/Nov/2017:02:02:47 +1100] GET /pdf/emt-refresher-class.html HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:02:49 +1100] GET /urea-urei-urease-01-M-urea---pdf.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:03:11 +1100] GET /pdf/typhoon-presentation.html HTTP/1.1 US
    168.235.194.192 - [26/Nov/2017:02:03:13 +1100] GET /pdf/astringents.html HTTP/1.1 US
    168.235.194.192 - [26/Nov/2017:02:03:13 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:03:18 +1100] GET /Trade-Secrets--JurisDiction--pdf.html HTTP/1.1 US
    196.190.64.27 - [26/Nov/2017:02:03:18 +1100] GET /pdf/antibiotics-residues.html HTTP/1.1 ET
    168.235.194.192 - [26/Nov/2017:02:03:33 +1100] GET /?s=astringents+and+emetics HTTP/1.1 US
    168.235.194.192 - [26/Nov/2017:02:03:34 +1100] GET /pdf/astringents-and-emetics.html HTTP/1.1 US
    168.235.194.192 - [26/Nov/2017:02:03:34 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:03:37 +1100] GET /pdf/crossing-red-sea.html HTTP/1.1 US
    40.77.167.11 - [26/Nov/2017:02:03:47 +1100] GET /Wilderness-Manager-Survey--pdf.html HTTP/1.1 US
    71.61.49.221 - [26/Nov/2017:02:03:47 +1100] GET /pdf/sbar.html HTTP/1.1 US
    71.61.49.221 - [26/Nov/2017:02:03:47 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    71.61.49.221 - [26/Nov/2017:02:03:47 +1100] GET /logo.jpg HTTP/1.1 US
    71.61.49.221 - [26/Nov/2017:02:03:48 +1100] GET /dmcaemail.png HTTP/1.1 US
    196.190.64.27 - [26/Nov/2017:02:03:55 +1100] GET //antibiotics-residues-web-Guidelines-for-Antibiotic-Residue-Avoidance--pdf.html HTTP/1.1 ET
    168.235.194.192 - [26/Nov/2017:02:03:56 +1100] GET /pdf/astringents.html HTTP/1.1 US
    168.235.194.192 - [26/Nov/2017:02:03:56 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    196.190.64.27 - [26/Nov/2017:02:04:00 +1100] GET /antibiotics-residues-web-Guidelines-for-Antibiotic-Residue-Avoidance--pdf.html HTTP/1.1 ET
    66.249.92.129 - [26/Nov/2017:02:04:03 +1100] GET /antibiotics-residues-web-Guidelines-for-Antibiotic-Residue-Avoidance--pdf.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:04:07 +1100] GET /pdf/hose-drill-fire-fighting-training.html HTTP/1.1 US
    209.126.120.38 - [26/Nov/2017:02:04:12 +1100] GET /pdf/sbar.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:04:18 +1100] GET /WAS-THE-ALAMO-A-DEFEAT-OR-A-VICTORY-OR-A-DEFEAT--pdf.html HTTP/1.1 US
    141.8.143.151 - [26/Nov/2017:02:04:18 +1100] GET /Quality-Tools--PCMAC--pdf.html HTTP/1.1 US
    40.77.167.11 - [26/Nov/2017:02:04:37 +1100] GET /pdf/environmental-impacts-of-pesticides-effects.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:04:48 +1100] GET /Fly-Eagle-Fly-PowerPoint-2--Jefferson-County-Schools-TN--pdf.html HTTP/1.1 US
    168.235.195.45 - [26/Nov/2017:02:04:59 +1100] GET /pdf/story-boarding.html HTTP/1.1 US
    168.235.195.45 - [26/Nov/2017:02:04:59 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    117.211.126.164 - [26/Nov/2017:02:06:05 +1100] GET /pdf/food-preservation-methods-.html HTTP/1.1 IN
    117.211.126.164 - [26/Nov/2017:02:06:06 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 IN
    117.211.126.164 - [26/Nov/2017:02:06:06 +1100] GET /logo.jpg HTTP/1.1 IN
    157.55.39.156 - [26/Nov/2017:02:06:06 +1100] GET /pdf/bearing-materials.html HTTP/1.1 US
    117.211.126.164 - [26/Nov/2017:02:06:14 +1100] GET /dmcaemail.png HTTP/1.1 IN
    157.55.39.228 - [26/Nov/2017:02:06:18 +1100] GET /Programme-6-Water-Resources-Management-Development------pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:06:36 +1100] GET /pdf/endocrine-disruption.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:06:48 +1100] GET /Pre-Algebra--pdf.html HTTP/1.1 US
    196.86.85.113 - [26/Nov/2017:02:07:06 +1100] GET /pdf/applied-linguistics.html HTTP/1.1 MA
    157.55.39.156 - [26/Nov/2017:02:07:06 +1100] GET /Nurse-to-Patient-Ratio--pdf.html HTTP/1.1 US
    196.86.85.113 - [26/Nov/2017:02:07:08 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 MA
    196.86.85.113 - [26/Nov/2017:02:07:09 +1100] GET /logo.jpg HTTP/1.1 MA
    196.86.85.113 - [26/Nov/2017:02:07:09 +1100] GET /dmcaemail.png HTTP/1.1 MA
    66.249.92.159 - [26/Nov/2017:02:07:11 +1100] GET /pdf/applied-linguistics.html HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:07:14 +1100] GET /pdf/on-thypoid.html HTTP/1.1 US
    196.86.85.113 - [26/Nov/2017:02:07:16 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 MA
    157.55.39.228 - [26/Nov/2017:02:07:18 +1100] GET /PowerPoint-Template-GuideStone-Corporate-Presentations--pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:07:38 +1100] GET /pdf/Embracing-Generational-Differences--pdf.html HTTP/1.1 US
    196.86.85.113 - [26/Nov/2017:02:07:41 +1100] GET //Applied-Linguistics--Ohio-State-University--pdf.html HTTP/1.1 MA
    196.86.85.113 - [26/Nov/2017:02:07:42 +1100] GET /Applied-Linguistics--Ohio-State-University--pdf.html HTTP/1.1 MA
    168.235.195.239 - [26/Nov/2017:02:07:42 +1100] GET /pdf/prokinetics-antiemetics.html HTTP/1.1 US
    168.235.195.239 - [26/Nov/2017:02:07:42 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    103.231.160.187 - [26/Nov/2017:02:07:43 +1100] GET /pdf/electrostatics-gauss-s-law-and-its-applications.html HTTP/1.1 BD
    103.231.160.187 - [26/Nov/2017:02:07:44 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 BD
    103.231.160.187 - [26/Nov/2017:02:07:44 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 BD
    103.231.160.187 - [26/Nov/2017:02:07:44 +1100] GET /dmcaemail.png HTTP/1.1 BD
    103.231.160.187 - [26/Nov/2017:02:07:44 +1100] GET /logo.jpg HTTP/1.1 BD
    66.249.92.158 - [26/Nov/2017:02:07:45 +1100] GET /pdf/electrostatics-gauss-s-law-and-its-applications.html HTTP/1.1 US
    40.77.167.11 - [26/Nov/2017:02:07:47 +1100] GET /pdf/roll-of-thunder-hear-my-cry.html HTTP/1.1 US
    103.231.160.187 - [26/Nov/2017:02:08:03 +1100] GET //electrostatics-gauss-s-law-and-its-applications-web--Principles-with-Applications-7--pdf.html HTTP/1.1 BD
    103.231.160.187 - [26/Nov/2017:02:08:03 +1100] GET /electrostatics-gauss-s-law-and-its-applications-web--Principles-with-Applications-7--pdf.html HTTP/1.1 BD
    103.231.160.187 - [26/Nov/2017:02:08:03 +1100] GET /download.jpg HTTP/1.1 BD
    66.249.92.158 - [26/Nov/2017:02:08:04 +1100] GET /electrostatics-gauss-s-law-and-its-applications-web--Principles-with-Applications-7--pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:08:06 +1100] GET /pdf/ricci-maternity.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:08:18 +1100] GET /Pathology--pcmac--pdf.html HTTP/1.1 US
    106.202.142.57 - [26/Nov/2017:02:08:23 +1100] GET /pdf/structure-of-atom-for-class-11th.html HTTP/1.1 IN
    106.202.142.57 - [26/Nov/2017:02:08:23 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 IN
    106.202.142.57 - [26/Nov/2017:02:08:24 +1100] GET /logo.jpg HTTP/1.1 IN
    106.202.142.57 - [26/Nov/2017:02:08:24 +1100] GET /dmcaemail.png HTTP/1.1 IN
    66.249.92.159 - [26/Nov/2017:02:08:25 +1100] GET /pdf/structure-of-atom-for-class-11th.html HTTP/1.1 US
    168.235.195.239 - [26/Nov/2017:02:08:27 +1100] GET /pdf/astringents.html HTTP/1.1 US
    168.235.195.239 - [26/Nov/2017:02:08:27 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    75.188.138.63 - [26/Nov/2017:02:08:28 +1100] GET /pdf/ethics-in-corrections.html HTTP/1.1 US
    75.188.138.63 - [26/Nov/2017:02:08:28 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    75.188.138.63 - [26/Nov/2017:02:08:28 +1100] GET /logo.jpg HTTP/1.1 US
    75.188.138.63 - [26/Nov/2017:02:08:28 +1100] GET /dmcaemail.png HTTP/1.1 US
    106.202.142.57 - [26/Nov/2017:02:08:28 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 IN
    66.249.92.158 - [26/Nov/2017:02:08:29 +1100] GET /pdf/ethics-in-corrections.html HTTP/1.1 US
    185.2.4.26 - [26/Nov/2017:02:08:30 +1100] GET /old/wp-admin/ HTTP/1.1 IT
    75.188.138.63 - [26/Nov/2017:02:08:31 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:08:36 +1100] GET /pdf/role-of-vitamins-and-minerals-in-food-processing.html HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:08:42 +1100] GET /12-cranial-nerves-mbbsclub-Cranial-Nerves-12-pair-of--pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:08:48 +1100] GET /pdf/psychosis-schizophrenia-and-antipsychotic-agents.html HTTP/1.1 US
    168.235.195.239 - [26/Nov/2017:02:08:58 +1100] GET /pdf/prokinetics-antiemetics.html HTTP/1.1 US
    168.235.195.239 - [26/Nov/2017:02:08:58 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    75.188.138.63 - [26/Nov/2017:02:09:04 +1100] GET //ethics-in-corrections-iupui-Title-PowerPoint-Presentation--Professional--pdf.html HTTP/1.1 US
    102.181.184.126 - [26/Nov/2017:02:09:04 +1100] GET /pdf/blood-parasites.html HTTP/1.1 -
    102.181.184.126 - [26/Nov/2017:02:09:04 +1100] GET /logo.jpg HTTP/1.1 -
    102.181.184.126 - [26/Nov/2017:02:09:04 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 -
    102.181.184.126 - [26/Nov/2017:02:09:04 +1100] GET /dmcaemail.png HTTP/1.1 -
    75.188.138.63 - [26/Nov/2017:02:09:04 +1100] GET /ethics-in-corrections-iupui-Title-PowerPoint-Presentation--Professional--pdf.html HTTP/1.1 US
    75.188.138.63 - [26/Nov/2017:02:09:05 +1100] GET /download.jpg HTTP/1.1 US
    66.249.92.159 - [26/Nov/2017:02:09:05 +1100] GET /ethics-in-corrections-iupui-Title-PowerPoint-Presentation--Professional--pdf.html HTTP/1.1 US
    66.249.92.158 - [26/Nov/2017:02:09:06 +1100] GET /pdf/blood-parasites.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:09:07 +1100] GET /pdf/first-impressions.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:09:17 +1100] GET /Part-III--Modes-of-Reproduction--Arkansas-State-University--pdf.html HTTP/1.1 US
    40.77.167.11 - [26/Nov/2017:02:09:37 +1100] GET /pdf/composites.html HTTP/1.1 US
    40.77.167.11 - [26/Nov/2017:02:09:47 +1100] GET /COMBINING-ECONOMICS-WITH-NETWORK-ENGINEERING--pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:12:47 +1100] GET /pdf/materials-requirements-planning--pdf.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:12:48 +1100] GET /pdf/sectional-anatomy-brain.html HTTP/1.1 US
    66.249.66.94 - [26/Nov/2017:02:12:52 +1100] GET /pdf/bat-pdf.html HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:13:01 +1100] GET /HANDWASHING-Timeless-Wisdom--A-Healthy-Habit--pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:13:07 +1100] GET /Common-Diseases-of-Small-Animals--Northwest-ISD--pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:13:17 +1100] GET /Nomadic-Empires-and-Eurasian-Integration--pdf.html HTTP/1.1 US
    2.31.250.240 - [26/Nov/2017:02:13:45 +1100] GET /pdf/pink-floyd-power-point.html HTTP/1.1 GB
    2.31.250.240 - [26/Nov/2017:02:13:45 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 GB
    2.31.250.240 - [26/Nov/2017:02:13:45 +1100] GET /logo.jpg HTTP/1.1 GB
    2.31.250.240 - [26/Nov/2017:02:13:45 +1100] GET /dmcaemail.png HTTP/1.1 GB
    2.31.250.240 - [26/Nov/2017:02:13:46 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 GB
    157.55.39.169 - [26/Nov/2017:02:13:48 +1100] GET /pdf/firefighter-safty-and-health.html HTTP/1.1 US
    66.249.92.129 - [26/Nov/2017:02:13:49 +1100] GET /pdf/pink-floyd-power-point.html HTTP/1.1 US
    34.207.174.103 - [26/Nov/2017:02:13:55 +1100] GET /pdf/pink-floyd-power-point.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:14:10 +1100] GET /pdf/fire-team-formations.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:14:11 +1100] GET /pdf/socialization-process.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:14:17 +1100] GET /Erythrocyte-Sedimentation-Rare--port-health-gov-ir--pdf.html HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:14:26 +1100] GET /FAST-Exam--lectures-shanyar-com--pdf.html HTTP/1.1 US
    95.233.1.98 - [26/Nov/2017:02:14:31 +1100] GET /wp-login.php HTTP/1.1 IT
    95.233.1.98 - [26/Nov/2017:02:14:33 +1100] GET / HTTP/1.1 IT
    71.61.49.221 - [26/Nov/2017:02:14:37 +1100] GET /pdf/sbar.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:14:37 +1100] GET /American-Heart-Association--Skidmore-College--pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:14:47 +1100] GET /Truth-in-Justice--stingraybobs-weebly-com--pdf.html HTTP/1.1 US
    66.249.66.65 - [26/Nov/2017:02:14:59 +1100] GET /logo.jpg HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:15:08 +1100] GET /Animal-VirusHost-Interactions--pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:15:17 +1100] GET /pdf/leadership-in-nursing-pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:15:47 +1100] GET /Presentation-title--Teachinglinks-net--pdf.html HTTP/1.1 US
    168.235.198.112 - [26/Nov/2017:02:15:49 +1100] GET /pdf/nozzles-pdf.html HTTP/1.1 US
    168.235.198.112 - [26/Nov/2017:02:15:49 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:15:51 +1100] GET /pdf/fatty-acids-beta-oxidation.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:15:54 +1100] GET /pdf/cantilever-beam-analysis.html HTTP/1.1 US
    168.235.198.112 - [26/Nov/2017:02:16:02 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:16:08 +1100] GET /pdf/anesthesia-for-thyroid-surgery.html HTTP/1.1 US
    168.235.198.112 - [26/Nov/2017:02:16:10 +1100] GET //nozzles-opwglobal-Why-Are-These-Nozzles-Found--pdf.html HTTP/1.1 US
    168.235.198.112 - [26/Nov/2017:02:16:11 +1100] GET /nozzles-opwglobal-Why-Are-These-Nozzles-Found--pdf.html HTTP/1.1 US
    168.235.198.112 - [26/Nov/2017:02:16:11 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:16:17 +1100] GET /pdf/english-pronunciation-exercises.html HTTP/1.1 US
    157.55.39.68 - [26/Nov/2017:02:16:27 +1100] GET /robots.txt HTTP/1.1 US
    40.77.167.11 - [26/Nov/2017:02:16:36 +1100] GET /Orthopaedic-special-tests-for-the-shoulder--Stort-Physio--pdf.html HTTP/1.1 US
    157.49.7.217 - [26/Nov/2017:02:16:39 +1100] GET /pdf/typhoid-vaccine.html HTTP/1.1 IN
    157.49.7.217 - [26/Nov/2017:02:16:39 +1100] GET /pdf/typhoid-vaccine.html HTTP/1.1 IN
    157.49.7.217 - [26/Nov/2017:02:16:40 +1100] GET /logo.jpg HTTP/1.1 IN
    157.49.7.217 - [26/Nov/2017:02:16:40 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 IN
    157.49.7.217 - [26/Nov/2017:02:16:40 +1100] GET /dmcaemail.png HTTP/1.1 IN
    51.15.44.92 - [26/Nov/2017:02:16:40 +1100] GET /Rocks-and-Minerals--Edgewood-High-School--pdf.html HTTP/1.1 GB
    157.49.7.217 - [26/Nov/2017:02:16:42 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 IN
    66.249.92.159 - [26/Nov/2017:02:16:43 +1100] GET /pdf/typhoid-vaccine.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:16:47 +1100] GET /PROYECTOS-DE-AHORRO-DE-ENERGIA-ELECTRICA--Luis-Alberto-Arcos------pdf.html HTTP/1.1 US
    168.235.198.112 - [26/Nov/2017:02:17:03 +1100] GET //nozzles-bae-A-Summary-of-Studies-Comparing--pdf.html HTTP/1.1 US
    168.235.198.112 - [26/Nov/2017:02:17:04 +1100] GET /nozzles-bae-A-Summary-of-Studies-Comparing--pdf.html HTTP/1.1 US
    168.235.198.112 - [26/Nov/2017:02:17:04 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:17:08 +1100] GET /pdf/test-construction.html HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:17:16 +1100] GET /The-Japan-Culture--Rice-University--pdf.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:17:17 +1100] GET /pdf/brodmans-areas.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:17:47 +1100] GET /Organisational-Buying-Behaviour--McGrawHill-Education--pdf.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:18:06 +1100] GET /pdf/organizational-behaviour-robbins-chapter-2.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:18:17 +1100] GET /pdf/fluid-management-in-children.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:18:19 +1100] GET /pdf/sociology-anthropology.html HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:18:37 +1100] GET /pdf/macro-minerals-pdf.html HTTP/1.1 US
    110.54.187.210 - [26/Nov/2017:02:18:39 +1100] GET /pdf/facts-and-opinion-lessons.html HTTP/1.1 PH
    110.54.187.210 - [26/Nov/2017:02:18:40 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 PH
    77.88.47.68 - [26/Nov/2017:02:18:40 +1100] GET /pdf/plant-nutrition.html HTTP/1.1 US
    110.54.187.210 - [26/Nov/2017:02:18:41 +1100] GET /logo.jpg HTTP/1.1 PH
    110.54.187.210 - [26/Nov/2017:02:18:41 +1100] GET /dmcaemail.png HTTP/1.1 PH
    110.54.187.210 - [26/Nov/2017:02:18:42 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 PH
    66.249.92.159 - [26/Nov/2017:02:18:44 +1100] GET /pdf/facts-and-opinion-lessons.html HTTP/1.1 US
    157.55.39.156 - [26/Nov/2017:02:18:47 +1100] GET /POSTPARTUM-DEPRESSION-BEYOND-THE-BLUES--Utah-Department-of------pdf.html HTTP/1.1 US
    67.111.46.50 - [26/Nov/2017:02:19:02 +1100] GET /pdf/GLASS-IONOMER-CEMENT--pdf.html HTTP/1.1 US
    67.111.46.50 - [26/Nov/2017:02:19:02 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    67.111.46.50 - [26/Nov/2017:02:19:02 +1100] GET /logo.jpg HTTP/1.1 US
    67.111.46.50 - [26/Nov/2017:02:19:02 +1100] GET /dmcaemail.png HTTP/1.1 US
    67.111.46.50 - [26/Nov/2017:02:19:04 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 US
    66.249.92.158 - [26/Nov/2017:02:19:04 +1100] GET /pdf/GLASS-IONOMER-CEMENT--pdf.html HTTP/1.1 US
    207.46.13.186 - [26/Nov/2017:02:19:07 +1100] GET /pdf/pstn.html HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:19:17 +1100] GET /pdf/seed-dormancy-and-its-importance-pdf.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:19:43 +1100] GET /pdf/sccm-2012-r2.html HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:19:47 +1100] GET /pdf/laser-angioplasty.html HTTP/1.1 US
    8.37.232.108 - [26/Nov/2017:02:20:01 +1100] GET /pdf/leukocyte-disorders.html HTTP/1.1 US
    8.37.232.108 - [26/Nov/2017:02:20:01 +1100] GET /dmcaemail.png HTTP/1.1 US
    8.37.232.108 - [26/Nov/2017:02:20:01 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    8.37.232.108 - [26/Nov/2017:02:20:01 +1100] GET /logo.jpg HTTP/1.1 US
    8.37.232.108 - [26/Nov/2017:02:20:04 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:20:07 +1100] GET /artificial-intelligence-2016-cs-AI-or-Computational-Intelligence-There--pdf.html HTTP/1.1 US
    8.37.235.34 - [26/Nov/2017:02:20:07 +1100] GET /pdf/basic-electrical-substation.html HTTP/1.1 US
    8.37.235.34 - [26/Nov/2017:02:20:07 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    8.37.235.34 - [26/Nov/2017:02:20:07 +1100] GET /dmcaemail.png HTTP/1.1 US
    8.37.235.34 - [26/Nov/2017:02:20:07 +1100] GET /logo.jpg HTTP/1.1 US
    8.37.235.34 - [26/Nov/2017:02:20:09 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:20:17 +1100] GET /pdf/operating-brts.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:20:18 +1100] GET /pdf/mrcp-paces.html HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:20:47 +1100] GET /pdf/1-corinthians.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:20:53 +1100] GET /pdf/electric-shock-causes-symptoms-treatment.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:21:11 +1100] GET /pdf/mk.html HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:21:17 +1100] GET /pdf/have-got-exercises.html HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:21:31 +1100] GET /pdf/types-of-cement-pdf.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:21:44 +1100] GET /pdf/postmodernism-theory.html HTTP/1.1 US
    40.77.167.11 - [26/Nov/2017:02:21:47 +1100] GET /Basic-Traffic-Stops--Career-and-Technical-Education-cteunt--pdf.html HTTP/1.1 US
    207.46.13.186 - [26/Nov/2017:02:22:07 +1100] GET /JET-PROPULSION--sseaimes-files-wordpress-com--pdf.html HTTP/1.1 US
    207.46.13.186 - [26/Nov/2017:02:22:17 +1100] GET /pdf/teton-dam-failure-presentations.html HTTP/1.1 US
    68.180.229.87 - [26/Nov/2017:02:22:26 +1100] GET /tree-falling-smithsgradesix-Trees-and-Forests-%E2%80%93-Falling--pdf.html HTTP/1.1 US
    194.187.171.53 - [26/Nov/2017:02:22:30 +1100] GET /favicon.ico HTTP/1.1 FR
    207.46.13.186 - [26/Nov/2017:02:22:37 +1100] GET /pdf/accounting-and-finance-for-bankers-jaiib.html HTTP/1.1 US
    207.46.13.186 - [26/Nov/2017:02:22:47 +1100] GET /Part-1--Page--Health-Care-Conference-Administrators-Home--pdf.html HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:22:50 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:23:11 +1100] GET /pdf/service-excellence.html HTTP/1.1 US
    207.46.13.186 - [26/Nov/2017:02:23:17 +1100] GET /pdf/beautiful.html HTTP/1.1 US
    207.46.13.186 - [26/Nov/2017:02:23:37 +1100] GET /pdf/usps-retirement.html HTTP/1.1 US
    131.253.25.254 - [26/Nov/2017:02:23:41 +1100] GET /pdf/nursing-and-neuro-assessment.html HTTP/1.1 US
    207.46.13.186 - [26/Nov/2017:02:23:47 +1100] GET /Year-10-Summer-Exams--pdf.html HTTP/1.1 US
    85.195.116.66 - [26/Nov/2017:02:23:57 +1100] GET / HTTP/1.0 DE
    54.82.61.140 - [26/Nov/2017:02:27:23 +1100] GET /pdf/medical-surgical-nursing.html HTTP/1.1 US
    68.180.229.87 - [26/Nov/2017:02:27:24 +1100] GET /fasteners-cengage-Understand-the-theory-behind-torquetoyield--pdf.html HTTP/1.1 US
    67.141.91.182 - [26/Nov/2017:02:27:25 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:27:39 +1100] GET /pdf/management-of-patients-with-neurologic-trauma.html HTTP/1.1 US
    207.46.13.186 - [26/Nov/2017:02:27:47 +1100] GET /Earth-Science-Chapter-12--pdf.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:28:17 +1100] GET /Wrist-and-Hand--groupf2-yolasite-com--pdf.html HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:28:17 +1100] GET /pdf/seasonality-of-reproduction.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:28:18 +1100] GET /pdf/cell-phone-infrastructure.html HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:28:37 +1100] GET /pdf/nfpa-20.html HTTP/1.1 US
    89.3.118.149 - [26/Nov/2017:02:28:42 +1100] GET /pdf/recombinant-proteins.html HTTP/1.1 FR
    89.3.118.149 - [26/Nov/2017:02:28:42 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 FR
    89.3.118.149 - [26/Nov/2017:02:28:42 +1100] GET /logo.jpg HTTP/1.1 FR
    89.3.118.149 - [26/Nov/2017:02:28:42 +1100] GET /dmcaemail.png HTTP/1.1 FR
    66.249.92.159 - [26/Nov/2017:02:28:44 +1100] GET /pdf/recombinant-proteins.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:28:47 +1100] GET /reakes-weebly-com--pdf.html HTTP/1.1 US
    89.3.118.149 - [26/Nov/2017:02:28:48 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 FR
    119.95.172.9 - [26/Nov/2017:02:28:49 +1100] GET /pdf/first-vita-plus.html HTTP/1.1 PH
    119.95.172.9 - [26/Nov/2017:02:28:50 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 PH
    119.95.172.9 - [26/Nov/2017:02:28:50 +1100] GET /logo.jpg HTTP/1.1 PH
    119.95.172.9 - [26/Nov/2017:02:28:50 +1100] GET /dmcaemail.png HTTP/1.1 PH
    34.230.8.39 - [26/Nov/2017:02:28:53 +1100] GET /pdf/recombinant-proteins.html HTTP/1.1 US
    68.180.229.87 - [26/Nov/2017:02:28:53 +1100] GET /N--pdf.html HTTP/1.1 US
    157.55.39.169 - [26/Nov/2017:02:29:07 +1100] GET /pdf/radiation-therapy.html HTTP/1.1 US
    66.249.92.129 - [26/Nov/2017:02:29:10 +1100] GET /pdf/first-vita-plus.html HTTP/1.1 US
    89.3.118.149 - [26/Nov/2017:02:29:17 +1100] GET /?s=recombinant+proteins HTTP/1.1 FR
    89.3.118.149 - [26/Nov/2017:02:29:17 +1100] GET /pdf/recombinant-proteins.html HTTP/1.1 FR
    157.55.39.228 - [26/Nov/2017:02:29:17 +1100] GET /OSEP-Update-on-Identification-and-Correction-of-Noncompliance------pdf.html HTTP/1.1 US
    119.95.172.9 - [26/Nov/2017:02:29:25 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 PH
    39.33.87.181 - [26/Nov/2017:02:29:30 +1100] GET /pdf/carbonate-reservoirs.html HTTP/1.1 PK
    39.33.87.181 - [26/Nov/2017:02:29:31 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 PK
    39.33.87.181 - [26/Nov/2017:02:29:31 +1100] GET /logo.jpg HTTP/1.1 PK
    39.33.87.181 - [26/Nov/2017:02:29:31 +1100] GET /dmcaemail.png HTTP/1.1 PK
    66.249.92.159 - [26/Nov/2017:02:29:33 +1100] GET /pdf/carbonate-reservoirs.html HTTP/1.1 US
    134.35.90.43 - [26/Nov/2017:02:29:35 +1100] GET //The-Egyptian-Pyramids--Mt--Lebanon-School-District--pdf.html HTTP/1.1 US
    134.35.90.43 - [26/Nov/2017:02:29:36 +1100] GET /The-Egyptian-Pyramids--Mt--Lebanon-School-District--pdf.html HTTP/1.1 US
    134.35.90.43 - [26/Nov/2017:02:29:36 +1100] GET /wp-content/themes/vivekweb/style.css HTTP/1.1 US
    134.35.90.43 - [26/Nov/2017:02:29:36 +1100] GET /logo.jpg HTTP/1.1 US
    134.35.90.43 - [26/Nov/2017:02:29:37 +1100] GET /dmcaemail.png HTTP/1.1 US
    77.88.47.68 - [26/Nov/2017:02:29:38 +1100] GET /pdf/istishna.html HTTP/1.1 US
    40.77.167.138 - [26/Nov/2017:02:29:38 +1100] GET /pdf/digital-newbie.html HTTP/1.1 US
    134.35.90.43 - [26/Nov/2017:02:29:39 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 US
    89.3.118.149 - [26/Nov/2017:02:29:42 +1100] GET //Recombinant-DNA--pdf.html HTTP/1.1 FR
    89.3.118.149 - [26/Nov/2017:02:29:43 +1100] GET /Recombinant-DNA--pdf.html HTTP/1.1 FR
    89.3.118.149 - [26/Nov/2017:02:29:44 +1100] GET /download.jpg HTTP/1.1 FR
    66.249.92.158 - [26/Nov/2017:02:29:44 +1100] GET /Recombinant-DNA--pdf.html HTTP/1.1 US
    54.226.130.166 - [26/Nov/2017:02:29:45 +1100] GET /Recombinant-DNA--pdf.html HTTP/1.1 US
    39.33.87.181 - [26/Nov/2017:02:29:45 +1100] GET //carbonate-reservoirs-carbonet-Seismic-is-but-one-part--pdf.html HTTP/1.1 PK
    39.33.87.181 - [26/Nov/2017:02:29:46 +1100] GET /carbonate-reservoirs-carbonet-Seismic-is-but-one-part--pdf.html HTTP/1.1 PK
    39.33.87.181 - [26/Nov/2017:02:29:46 +1100] GET /download.jpg HTTP/1.1 PK
    66.249.92.158 - [26/Nov/2017:02:29:47 +1100] GET /carbonate-reservoirs-carbonet-Seismic-is-but-one-part--pdf.html HTTP/1.1 US
    157.55.39.228 - [26/Nov/2017:02:29:47 +1100] GET /Classification-of-EEG-signals--pdf.html HTTP/1.1 US
    119.95.172.9 - [26/Nov/2017:02:29:49 +1100] GET /pdf/first-vita-plus.html HTTP/1.1 PH
    39.33.87.181 - [26/Nov/2017:02:29:56 +1100] GET /wp-content/themes/vivekweb/favicon.ico HTTP/1.1 PK

答案1

GNUAWK解决方案(仅获取当前日期的国家/地区代码计数):

awk 'BEGIN{ curr_d=strftime("%d/%b/%Y", systime()) }
     $3~"^\\["curr_d{ cc[$8]++ }
     END{ for(i in cc) print i":"cc[i] }' /var/log/mywebsite.log > /home/mywebsite/www/countries.txt

答案2

awk '{ a[$NF]++; }; END { for(key in a) print key ":" a[key]; }' inputfile

答案3

使用关联数组的 ba​​sh 答案:

#!/bin/bash

declare -A codes

while IFS= read -r line; do
   country="${line##* }"
   if [[ -n ${codes[$country]} ]]; then
      ((codes[$country]++))
   else
      codes[$country]=1
   fi
done < <(grep "$(date +%d/%b/%Y)" /var/log/mywebsite.log)

for country in ${!codes[@]}; do
   echo "$country: ${codes[$country]}"
done

exit

相关内容