LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-09-2015, 03:40 PM   #1
dingo-den
Member
 
Registered: Aug 2005
Location: Apr-Oct Enderby, BC Canada Oct-Mar Somewhere warm
Distribution: Debian 6 and 7
Posts: 46

Rep: Reputation: 0
Help parsing a text document.


I am trying to get a warning from a document when it arrises. The text I am trying to find is as follows, and I am trying to save the SEVERE THUNDERSTORM WATCH IN EFFECT and HEAT WARNING IN EFFECT to a variable.

<div id="warning">
<h2>
<a href="/warnings/report_e.html?on41#2013186891713292526201509070503">SEVERE THUNDERSTORM WATCH IN EFFECT</a>
</h2>
<h2>
<a href="/warnings/report_e.html?on41#1949176161926550836201509050503">HEAT WARNING IN EFFECT</a>
</h2>

I just can't get my head around this stuff. I have been trying for a long time to get it myself but I am not a programmer and this stuff is beyond me. This is the latest thing I tried but it does not work ?


# ----- added warning
WARN3=`cat /var/www/localhost/htdocs/scripts/weather/weather_temp_live.txt | grep "warnings/report_e" | awk -F'>' '{print $3}' | sed -e 's/<\/a/ /g'`

WARN33=`cat /var/www/localhost/htdocs/scripts/weather/weather_temp_live.txt | grep -m2 "warnings/report_e" | awk -F'>' '{print $7}' | sed -e 's/<\/a/ /g'`
echo "This is the first warning" $WARN3
echo "This is the second warning" $WARN33
# -- warning finish



Any help would be appresiated.

Last edited by dingo-den; 09-09-2015 at 03:46 PM.
 
Old 09-09-2015, 04:18 PM   #2
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
With that data in the file called storm.dat I did this

awk -F">" '{print $2}' storm.dat |sed 's/<\/a//'

to get this


SEVERE THUNDERSTORM WATCH IN EFFECT


HEAT WARNING IN EFFECT
 
Old 09-09-2015, 04:20 PM   #3
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
And to assign it this should work:

cat storm.dat|grep SEV|awk -F">" '{print $2}' |sed 's/<\/a//'
 
Old 09-09-2015, 06:53 PM   #4
dingo-den
Member
 
Registered: Aug 2005
Location: Apr-Oct Enderby, BC Canada Oct-Mar Somewhere warm
Distribution: Debian 6 and 7
Posts: 46

Original Poster
Rep: Reputation: 0
Hi

Thanks for the replies but I am not using storm.dat and don't know if it applies to Canada? I am using the file downloaded from here which is the Canadian Government weather page .

http://weather.gc.ca/city/pages/on-118_metric_e.html
 
Old 09-09-2015, 07:18 PM   #5
dingo-den
Member
 
Registered: Aug 2005
Location: Apr-Oct Enderby, BC Canada Oct-Mar Somewhere warm
Distribution: Debian 6 and 7
Posts: 46

Original Poster
Rep: Reputation: 0
OK I played around some more with the solutions that you gave and it now works with this:

WARN3=`cat /var/www/localhost/htdocs/scripts/weather/weather_temp_live.txt | grep "warnings/report_e" | awk -F'>' '{print $2}' | sed 's/<\/a/ /g'`

Thanks for your help.
 
Old 09-09-2015, 11:52 PM   #6
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
Quote:
Originally Posted by dingo-den View Post
OK I played around some more with the solutions that you gave and it now works with this:

WARN3=`cat /var/www/localhost/htdocs/scripts/weather/weather_temp_live.txt | grep "warnings/report_e" | awk -F'>' '{print $2}' | sed 's/<\/a/ /g'`

Thanks for your help.
Glad it works. Also I detected a useless use of cat. Not a serious issue at all. You don't need to use cat.

WARN3=`grep "warnings/report_e" /var/www/localhost/htdocs/scripts/weather/weather_temp_live.txt | awk -F'>' '{print $2}' | sed 's/<\/a/ /g'`

I might also place the filename in a variable so the line is shorter and easier to read. But that's your choice.
 
Old 09-10-2015, 12:25 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 17,152

Rep: Reputation: 2626Reputation: 2626Reputation: 2626Reputation: 2626Reputation: 2626Reputation: 2626Reputation: 2626Reputation: 2626Reputation: 2626Reputation: 2626Reputation: 2626
awk is much more flexible than that - no need for anything else in this case.
Code:
awk -F"[<>]" '/warnings\/report_e/ {print $3}' input.file
 
Old 09-16-2015, 04:04 PM   #8
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
awk is much more flexible than that - no need for anything else in this case.
Code:
awk -F"[<>]" '/warnings\/report_e/ {print $3}' input.file
Right. So now it's a useless use of cat and grep.
 
  


Reply

Tags
awk


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I generate a new text file for each line of text in a document? dio Linux - Newbie 6 06-05-2012 03:31 PM
How to copy text from vmware from linux text terminal to word document in windows? meandsushil Linux - Newbie 40 01-12-2011 07:06 AM
[SOLVED] Parsing text and combining the parsed text zeratul111 Linux - Newbie 6 10-28-2010 01:46 PM
I need help parsing text from a text file rsmccain Linux - General 2 01-05-2006 03:43 PM
Text parsing question bruoersolitario Linux - General 4 04-15-2004 03:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration