Problem I am having with grep
by gilesaj001 from LinuxQuestions.org on (#6GQCA)
I am not a programmer but I have a web site at https://parliamenthillottawa.com. I have a file that contains formatted text named weather-data-advisory-temp.txt and I want to find the word "Advisory" and save the line that it is in and the next 2 number of lines.
If I run Code:grep 'Advisory' --after-context=2 weather-data-advisory-temp.txt I get what I want
Quote:
If there is an Advisory the Advisory is a paragraph.
If I try to save that command to a variable Code: alert=$(grep 'Advisory' --after-context=2 weather-data-advisory-temp.txt) the results include all the file names in the folder and the text ??
Quote:
Can someone tell me where I am going wrong or give me another solution.
Thanks
An extract of the text file is here and the text is bolded:
Quote:
If I run Code:grep 'Advisory' --after-context=2 weather-data-advisory-temp.txt I get what I want
Quote:
" Weather Advisory ended for: * City of Ottawa" |
If I try to save that command to a variable Code: alert=$(grep 'Advisory' --after-context=2 weather-data-advisory-temp.txt) the results include all the file names in the folder and the text ??
Quote:
echo $alert Weather Advisory ended for: backup-server.sh move-weather-advisory-data.sh move-weather-data.sh rsa.pass.txt weather-data-advisory-temp.txt weather-data-temp.txt weather-update-advisory-lynx.sh weather-update-lynx.sh City of Ottawa |
Thanks
An extract of the text file is here and the text is bolded:
Quote:
#[1]ATOM feed for Weather Alert - Environment Canada * [2]Skip to main content * [3]Skip to "About government" Language selection * [4]Franiais [5]Government of Canada / Gouvernement du Canada Search Search website ___________________________ (BUTTON) Search Menu (BUTTON) Main Menu * [6]Jobs and the workplace * [7]Immigration and citizenship * [8]Travel and tourism * [9]Business and industry * [10]Benefits * [11]Health * [12]Taxes * [13]Environment and natural resources * [14]National security and defence * [15]Culture, history and sport * [16]Policing, justice and emergencies * [17]Transport and infrastructure * [18]Canada and the world * [19]Money and finances * [20]Science and innovation You are here: 1. [21]Home 2. [22]Environment and natural resources 3. [23]Weather information 4. [24]Alerts [25]Edit My ProfileMy Weather Profile [26]Weather shortcuts Access city ____________________ (BUTTON) Go (BUTTON) Last updated5:31 AM local Tue 28 Nov 2023 Alerts for: Ottawa North - Kanata - Orlians Statements 11:50 PM EST Monday 27 November 2023 Weather Advisory ended for: * City of Ottawa Follow: * [27]'Regional ATOM feed' | translate Regional ATOM Weather shortcuts (BUTTON) Add to shortcuts (BUTTON) Organize shortcuts Organize Shortcuts Select to drag and drop, rename or delete. No shortcuts * [28]Report Severe Weather * [29]Canadian Weather * [30]Weather Radar - Canada * [31]Satellite - Canada * [32]Marine - Canada * [33]Air Quality * [34]Canadian Ice Service * [35]Seasonal forecasts * [36]Extended forecast * [37]Public Alerts - Canada * [38]Lightning * [39]Hurricane * [40]Weather Summaries * [41]Hazardous Weather * [42]Global and Regional forecast models * [43]Astronomy * [44]Water Level and Flow * [45]Historical Climate Data * [46]Aviation * [47]Guide to Public forecasts * [48]Guide to Marine forecasts * [49]Guide to Air Quality forecasts * [50]Canadian Centre for Climate Services Library * [51]Wind Chill and Humidex Calculators * [52]Weather and your health Add this page Name ____________________ (BUTTON) Save (BUTTON) Cancel (BUTTON) Rename (BUTTON) Delete (BUTTON) Save i Add to shortcuts The name you have entered for the shortcut already exists on your Weather shortcuts menu. Would you like to overwrite it? (BUTTON) Yes (BUTTON) No i Rename shortcut There is already a shortcut with the same name in this list. Do you want to rename "link" to "link(2)"? (BUTTON) Yes (BUTTON) No i Add to shortcuts Your shortcut list has reached the maximum size of 30 (BUTTON) Close How to use * Add to shortcuts + Go to the desired page on the site, open the Weather shortcuts menu and click on the "Add to shortcuts" button + Page name will display in the "Add this page" window, the name can be changed by highlighting the text and entering the desired name + Click on the "Save" button to add the link to the list + Click on the "X" button to close the panel * Delete a link + Click on the "Organize shortcuts" button + Select the link to delete + Click on the "Delete" button to remove the link from the list + Click on the "Close" button to save the change * Move a link up/down the list + Click on the "Organize shortcuts" button + Click and hold the link and move to new location in the list + Click on the "Close" button to save the change * Rename a link + Click on the "Organize shortcuts" button + Select the link to rename + Click on the "Rename" button and change the link name + Click the enter or tab key + Click on the "Close" button to save the change * Keyboard navigation + Use the Tab key to move to a button or link + Use the Enter key to click on buttons or links + Organize shortcuts navigation o Use the Up key to select the link above. If none are selected, it will select the first link. o Use the Down key to select the link below. If none are selected, it will select the last link. o Use the Page Up key to move a selection up in the list. o Use the Page Down key to move a selection down in the list. * Restore default list Warning: Clicking on the button below will remove all your customized links. (BUTTON) Restore default links Customized Weather shortcuts Save your customized list as a bookmark. Copy/paste or click on the link below then when the page displays, you can bookmark the page using the web browser. Bookmarking your customized list will allow you to access it even if the local storage on your device is erased. (BUTTON) Close [53]Feedbackabout this web site Date modified: 2023-10-24 About this site Environment and natural resources * [54]Contact us * [55]Our environment * [56]Nature-based climate solutions Government of Canada * [57]All contacts * [58]Departments and agencies * [59]About government Themes and topics * [60]Jobs * [61]Immigration and citizenship * [62]Travel and tourism * [63]Business * [64]Benefits * [65]Health * [66]Taxes * [67]Environment and natural resources * [68]National security and defence * [69]Culture, history and sport * [70]Policing, justice and emergencies * [71]Transport and infrastructure * [72]Canada and the world * [73]Money and finance * [74]Science and innovation * [75]Indigenous peoples * [76]Veterans and military * [77]Youth Government of Canada Corporate * [78]Social media * [79]Mobile applications * [80]About Canada.ca * [81]Terms and conditions * [82]Privacy Symbol of the Government of Canada References 1. https://weather.gc.ca/warnings/rss/b.../onrm104_e.xml 2. https://weather.gc.ca/warnings/repor...rm104=#wb-cont 3. https://weather.gc.ca/warnings/repor...rm104=#wb-info 4. https://meteo.gc.ca/warnings/report_f.html?onrm104= 5. http://www.canada.ca/en.html 6. https://www.canada.ca/en/services/jobs.html 7. https://www.canada.ca/en/services/im...tizenship.html 8. https://travel.gc.ca/ 9. https://www.canada.ca/en/services/business.html 10. https://www.canada.ca/en/services/benefits.html 11. https://www.canada.ca/en/services/health.html 12. https://www.canada.ca/en/services/taxes.html 13. http://www.canada.ca/en/services/environment.html 14. https://www.canada.ca/en/services/defence.html 15. https://www.canada.ca/en/services/culture.html 16. https://www.canada.ca/en/services/policing.html 17. https://www.canada.ca/en/services/transport.html 18. http://international.gc.ca/world-mon....aspx?lang=eng 19. https://www.canada.ca/en/services/finance.html 20. https://www.canada.ca/en/services/science.html 21. http://www.canada.ca/en.html 22. http://www.canada.ca/en/services/environment.html 23. https://weather.gc.ca/ 24. https://weather.gc.ca/mainmenu/alert_menu_e.html 25. https://weather.gc.ca/myprofile/index_e.html 26. https://weather.gc.ca/warnings/repor...vourites-panel 27. https://weather.gc.ca/rss/battleboard/onrm104_e.xml 28. https://www.canada.ca/en/environment.../overview.html 29. https://weather.gc.ca/canada_e.html 30. https://weather.gc.ca/index_e.html?layers=,radar 31. https://weather.gc.ca/satellite/index_e.html 32. https://weather.gc.ca/marine/index_e.html 33. https://weather.gc.ca/mainmenu/airquality_menu_e.html 34. https://www.canada.ca/en/environment...onditions.html 35. https://weather.gc.ca/saisons/index_e.html 36. https://weather.gc.ca/forecast/public_bulletins_e.html 37. https://weather.gc.ca/index_e.html?layers=alert 38. https://weather.gc.ca/lightning/index_e.html 39. https://weather.gc.ca/hurricane/index_e.html 40. https://weather.gc.ca/warnings/weathersummaries_e.html 41. https://www.canada.ca/en/environment...r-hazards.html 42. https://weather.gc.ca/model_forecast/model_e.html 43. https://weather.gc.ca/astro/index_e.html 44. https://www.canada.ca/en/environment...ng/survey.html 45. https://climate.weather.gc.ca/index_e.html 46. https://flightplanning.navcanada.ca/...n&TypeDoc=html 47. https://www.canada.ca/en/environment...lic/guide.html 48. https://www.canada.ca/en/environment...forecasts.html 49. https://www.canada.ca/en/environment...forecasts.html 50. https://climate-change.canada.ca/climate-library 51. https://weather.gc.ca/windchill/wind_chill_e.html 52. https://www.canada.ca/en/environment...er-health.html 53. https://weather.gc.ca/mainmenu/contact_us_e.html 54. https://weather.gc.ca/mainmenu/contact_us_e.html 55. https://www.canada.ca/en/services/en...vironment.html 56. https://www.canada.ca/en/services/en...solutions.html 57. https://www.canada.ca/en/contact.html 58. https://www.canada.ca/en/government/dept.html 59. https://www.canada.ca/en/government/system.html 60. https://www.canada.ca/en/services/jobs.html 61. https://www.canada.ca/en/services/im...tizenship.html 62. https://travel.gc.ca/ 63. https://www.canada.ca/en/services/business.html 64. https://www.canada.ca/en/services/benefits.html 65. https://www.canada.ca/en/services/health.html 66. https://www.canada.ca/en/services/taxes.html 67. http://www.canada.ca/en/services/environment.html 68. https://www.canada.ca/en/services/defence.html 69. https://www.canada.ca/en/services/culture.html 70. https://www.canada.ca/en/services/policing.html 71. https://www.canada.ca/en/services/transport.html 72. http://international.gc.ca/world-mon....aspx?lang=eng 73. https://www.canada.ca/en/services/finance.html 74. https://www.canada.ca/en/services/science.html 75. https://www.canada.ca/en/services/in...s-peoples.html 76. https://www.canada.ca/en/services/ve...-military.html 77. https://www.canada.ca/en/services/youth.html 78. https://www.canada.ca/en/social.html 79. https://www.canada.ca/en/mobile.html 80. https://www.canada.ca/en/government/about.html 81. https://www.canada.ca/en/transparency/terms.html 82. https://www.canada.ca/en/transparency/privacy.html |