how to replace html line into a command line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to replace html line into a command line?
# 1  
Old 04-22-2012
how to replace html line into a command line?

hi!

i'm trying to use sed for this, but i'm struggling a lot. i want to convert

Code:
<div class="middle" id="middle">Friday, 20 April 2012<br /> <span class="hex">728CB5</span> <br /></div>

into

Code:
fbsetroot -solid '#728CB5'

considering all information between 'id="middle">' and '<br /> <span' should be ignored or removed earlier (because it may vary), or only considering the information between '="hex">' and '</span>'

(that html line above were obtained from
Code:
wget http://www.chromatweet.com/index.html -O _.html && cat _.html | grep hex | grep middle

) (added some spaces on the url above because this forum is blocking urls in messages like this)

thanks in advance! Smilie

---------- Post updated at 12:15 PM ---------- Previous update was at 10:26 AM ----------

this code is working, but if you know some way to make it simpler, be welcome suggesting
Code:
wget http://www.chromatweet.com/index.html -O _.html
cat _.html | grep hex | grep middle | sed -n -e 's/.*hex\"\(.*\)\/span.*/\1/p' | sed -e 's/>/fbsetroot -solid \x27#/' | sed -e 's/</\x27/' > _.sh
chmod +x _.sh && bash _.sh && rm _.sh _.html


Last edited by Scrutinizer; 04-22-2012 at 03:44 PM.. Reason: Additional code tags
# 2  
Old 04-22-2012
Hi try:
Code:
wget http://www.chromatweet.com/index.html -O - 2>/dev/null | awk '/middle/{gsub(/<[^>]*>/,x);print "fbsetroot -solid \x27#" $NF "\x27"}'


Last edited by Scrutinizer; 04-22-2012 at 03:54 PM..
# 3  
Old 04-22-2012
Hi nitrofurano,

One way with perl:
Code:
$ perl -MLWP::Simple -e '
    if ( ( grep { m/middle/ && m/hex/ } split /\n/, get( q[http://www.chromatweet.com/index.html] ) )[0] =~ m/"hex">(\d+)</ ) { 
        system( q[fbsetroot], q[-solid], qq['#$1'] ) 
    }
'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace outliers in bash, with one-line command?

I need to replace outliers from time series, an example below (outlier at x-position 386). The problem is that I do not want to smooth this line, I would like to replace the outlier with, for instance, an average value from the two consecutive values (i.e., average value from positions 385 and... (2 Replies)
Discussion started by: Gery
2 Replies

2. Shell Programming and Scripting

Replace values in script reading line by line using sed

Hi all, Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE. for pa in PA_VALUE blah blah do for pb in PB_VALUE blah blah do I have a text file with two columns of values for PA and PB. 14.5 16.7 7.8 9.5 5.6 3.6 etc etc I would like to read this... (7 Replies)
Discussion started by: crimsonengineer
7 Replies

3. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

4. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

5. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

6. Shell Programming and Scripting

sed command to replace a word with new line and /

Hi, I have been trying to replace the key word "SQL> spool off " with "/ show errors" with out double quotes in all the files in a directory. above show erros should be displayed next line Could you please help me how to do that. I have tried something like this... (3 Replies)
Discussion started by: pointers
3 Replies

7. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

8. Shell Programming and Scripting

Replace space, that is not in html tags <> with new line using sed

Hi, I am working on transforming html code text into the .vert text format. I want to use linux utility sed. I have this regexp which should do the work: s/ \(?!*>\)/\n/g. I use it like this with sed: echo "you <we try> there" | sed 's/ \(?!*>\)/\n/g' ... The demanded output should be: you <we... (5 Replies)
Discussion started by: matt1311
5 Replies

9. AIX

Command line/Script to send E-mail with HTML body and binary attachment

I apoligize for the cross-post but I'm not getting much in the way of help in the dummies forum: I'm trying to script sending an e-mail message on an AIX 5.x server with the following requirements: 1. command line switch to specify file name containing message body in HTML format 2. command... (3 Replies)
Discussion started by: G-Man
3 Replies

10. UNIX for Dummies Questions & Answers

replace text in a file from the command line...

I am having to do a lot of searching thru files to replace words. Is there a command that i can run that will alow me to hunt thru a group of files and replace one word with another without having to open each file idividually? -thanks;) (1 Reply)
Discussion started by: dudboy
1 Replies
Login or Register to Ask a Question