sed with escapes AND spaces?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed with escapes AND spaces?
# 1  
Old 08-01-2011
Error sed with escapes AND spaces?

It's been covered in lots of places, and I have banged on it for about an hour and I am not making any headway on this particular string.

A weather-related web page I want to monitor has text on the screen, but it changes. Right now, the page has "None issued by this office recently." but in 2 hours it could say "Noah, Build me an ark". So to get around the "None issued by this office recently." blurb, I though I'd use "sed /from/,/to/..." but I am stuck on all the escapes and :[blank]s.

These are the elements that I "think" will do what I need for the "sed /from/,/to/"
Code:
<!-- // CONTENT STARTS HERE -->
<!-- // CONTENT ENDS HERE -->

I used
Code:
sed -n '/LSRMKX/,/RKAPELA/p'
sed -n '/HWOMKX/,/\$\$/p'

on 2 web pages that have weather data/content and that works wonderfully.

I need some sed.fu to sed between these 2 elements/strings
starting at
Code:
<!-- // CONTENT STARTS HERE -->

and ending at
Code:
<!-- // CONTENT ENDS HERE -->

I believe that would be a more comprehensive solution to my task.

What I have tried in shown here.
SUSE Paste

GNU sed version 4.2.1
GNU bash, version 4.1.10

Thank you for your time.
# 2  
Old 08-01-2011
If I understand right you need just to change your delimeters:
Code:
sed -n '\|START|,\|END|p' INPUTFILE

Or if you want to get only lines between START and END then
Code:
sed -n '\|START|,\|END| { \|START|d; \|END|d; p }' INPUTFILE


Last edited by yazu; 08-01-2011 at 10:42 AM.. Reason: s/you/I/
# 3  
Old 08-01-2011
Thansk yazu:

Here's the page:
National Weather Service Text Product Display

I need any/all text in the source after
Code:
<hr noshade="noshade" align="left" size="1" width="520"></div>

here's another url I did manage to clean up for this task:
http://forecast.weather.gov/product....n=1&glossary=0
and what I used to clean it is:
Code:
sed -n '/LSRMKX/,/RKAPELA/p'

Thank you for your time.
# 4  
Old 08-01-2011
To get the last <div>...</div> between $start and $end:
Code:
$ start='<!-- // CONTENT STARTS HERE -->'
$ end='<!-- // CONTENT ENDS HERE -->'
$ curl -s 'http://www.crh.noaa.gov/product.php?site=MKX&product=SVR&issuedby=MKX' \
  | sed -n '\#'"$start"'#, \#'"$end"'# p'  | tr '\n' ' ' | sed 's#^.*\(<div>.*</div>\).*$#\1#'
<div><span style="color:Red;">None issued by this office recently.</span></div>

This User Gave Thanks to yazu For This Post:
# 5  
Old 08-01-2011
Wrench

Thanks yazu,

I took another approach and wrote a shutdown script for "Severe Thunderstorms" using conkyForest, a shell script and a cron for the "user"

Linux Mint Forums &bull; View topic - Automate shutdown during thunderstorm warning script is the script/instructions.

I didn't mean to waste your time.

Thank you very much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can't remove spaces with sed when calling it from sh -c

The following command works echo "some text with spaces" | sh -c 'sed -e 's/t//g''But this doesn't and should echo "some text with spaces" | sh -c 'sed -e 's/ //g''Any ideas? (3 Replies)
Discussion started by: Tribe
3 Replies

2. Shell Programming and Scripting

How to prepend spaces using sed command..?

hi all , i had the below sed command to append header at the starting of my output file .... sed -i -e '1i saikumar suresh hemanth' output.txt i want to append spaces to the Name saikumar how can i append with in this command ....? (1 Reply)
Discussion started by: hemanthsaikumar
1 Replies

3. Emergency UNIX and Linux Support

Removing ONLY UNIQUE blank spaces with sed?

Hi, I have data that looks similar to this: In which the sentences are written horizontally and the beginning of a sentence is indicated by a 1 in the first column and the number increments until the last item of the sentence. The end of the sentence and the beginning of the next is then indicate... (1 Reply)
Discussion started by: owwow14
1 Replies

4. Shell Programming and Scripting

[Solved] Backtick and escapes

Hello all, I have a problem with a bash script. It contains an MySQL query, which when I run it 'as is', executes without a problem. When, however, I try to get it to assign its output to a variable, using the backtick, I get errors. So .. /usr/bin/mysql -N -B mydatabase -e 'SELECT... (3 Replies)
Discussion started by: davidm123SED
3 Replies

5. Shell Programming and Scripting

sed remove newlines and spaces

Hi all, i am getting count from oracle 11g by spooling it to a file. Now there are some newline characters and blank spaces i need to remove these. pl provide me a awk/sed solution. the spooled file is attached. i tried this.. but not getting req o/p (6 Replies)
Discussion started by: rishav
6 Replies

6. Shell Programming and Scripting

tr and sed remove spaces. how to stop this?

if the answer is obvious, sorry, I'm new here. anyway, I'm using tr to encrypt with rot-13: echo `cat $script | tr 'a-zA-Z' 'n-za-mN-ZA-M'` > $script it works, but it removes any consecutive spaces so that there is just one space between words. I've had this problem before while using sed to... (5 Replies)
Discussion started by: Trichopterus
5 Replies

7. UNIX for Dummies Questions & Answers

Tab spaces with sed

Anyone know how to represent tabs when doing subsitutions in sed? I have tried using \t but it doesn't seem to work. (11 Replies)
Discussion started by: handak9
11 Replies

8. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this I'm using sed to remove only the leading spaces in a file bash-280R# cat foofile some text some text some text some text some text bash-280R# bash-280R# sed 's/^ *//' foofile > foofile.use bash-280R# cat foofile.use some text some text some text... (6 Replies)
Discussion started by: laser
6 Replies

9. UNIX for Dummies Questions & Answers

how to use sed command with alphabetical and spaces?

If have a problem with this command: name="toe der" echo $name | sed -e 's/]//g' it will become: toeder how to make it back to original? (7 Replies)
Discussion started by: elenatec
7 Replies

10. Shell Programming and Scripting

how to remove spaces in a string using sed.

Hello, I have the following to remove spaces from beginning and end of a string. infile=`echo "$infilename" | sed 's/^ *//;s/ *$//` How do I modify the above code to remove spaces from beginning, end and in the middle of the string also. ex: ... (4 Replies)
Discussion started by: radhika
4 Replies
Login or Register to Ask a Question