Hot answers tagged

50

There are many different versions of mail around. When you go beyond mail -s subject to1@address1 to2@address2 <body (for sending, that's all POSIX guarantees — and even -s didn't exist in the old days), they tend to have different command line options. Adding an additional header isn't always easy. With some mailx implementations, e.g. from mailutils ...


42

lynx has a "dump" mode, which you can use with watch: $ watch lynx https:/www.google.com -dump From man lynx: -dump dumps the formatted output of the default document or those specified on the command line to standard output. Unlike interactive mode, all documents are processed. This can be used in the ...


24

The html-xml-utils package, available in most major Linux distributions, has a number of tools that are useful when dealing with HTML and XML documents. Particularly useful for your case is hxselect which reads from standard input and extracts elements based on CSS selectors. Your use case would look like: hxselect '#the_div_id' <file You might get a ...


14

You can do this with mutt's mime support. In addition, you can use this with Autoview to denote two commands for viewing an attachment, one to be viewed automatically, the other to be viewed interactively from the attachment menu. Essentially, you include two options in your mailcap file1. text/html; luakit '%s' &; test=test -n "$DISPLAY"; needsterminal; ...


9

You do have a requirement that warrants an HTML parser: you need to parse HTML. Perl's HTML::TreeBuilder, Python's BeautifulSoup and others are easy to use, easier than writing complex and brittle regular expressions. perl -MHTML::TreeBuilder -le ' $html = HTML::TreeBuilder->new_from_file($ARGV[0]) or die $!; foreach ($html->look_down(_tag =&...


8

As the HTTP spec (and the error message from your HTTP server) specify, you need one blank line between the HTTP headers and the body, otherwise the server doesn't know where the headers end and the body begins. From RFC 2616 (emphasis my own): Request (section 5) and Response (section 6) messages use the generic message format of RFC 822 [9] for ...


8

Even if you fix the errors in your shell syntax as Braiam's answer correctly identifies, you will never get this to really work right. At best you might find a few mistakes of the sort you know you make; but you will never get grep to reliably find broken tags of the sort you might not have already noticed you are breaking. To do this right you need to use ...


8

With GNU recode: recode html < file


8

Instead of a text processing tool like sed/grep, use a tool that understands HTML. For example, in xsh, you can open :F html file.html ; delete //tr[td='TESTCASE-002'] ; save :b ; You have to fix the file first, though - remove the misplaced </body> and </head> endtags.


7

Why use awk? sed is better at this: sed -ne 's/.*\(http[^"]*\).*/\1/p' < foo.js


7

Though this goes against my better judgment I'll post it (sed part). That is: if it is for a quick and dirty fix go ahead. If it is a bit more serious or something you are going to do frequently etc. Use something else like python, perl etc. where you do not rely on regular expressions, but rather modules to handle HTML documents. One of the simpler ways ...


7

With a recent version of xclip (the -t option was added in 2010 but not released yet AFAICT, so you'd need to get it from subversion, or use the one packaged in Debian). xclip -o -selection clipboard -t text/html | pandoc -r html -w markdown And if you want to make that back into the clipboard: xclip -o -selection clipboard -t text/html | pandoc -r ...


7

As it turns out, the link in the question hinted at a working solution in the form of xclip: pandoc -S file.mkd | xclip -t text/html ...and then I can paste it straight into the document in libreoffice, properly formatted. This works with the versions of the programs in the Ubuntu 13.04 repositories (pandoc 1.10.1 and xclip 0.12) -- the -t option for ...


7

w3m is another program that has a --dump option. It is the backend Emacs' most popular web browser.


6

#!/bin/sh ( echo "To: me@example.com" echo "Subject: hello" echo "Content-Type: text/html" echo echo "<html><b><font size='7'>H</font>ello</b></html>" echo ) | /usr/sbin/sendmail -t


6

That's OS/distribution/desktop-environment dependent, but in many places, you'll find a xdg-open command that does just that.


6

This will do the trick: echo "<table>" ; print_header=true while read INPUT ; do if $print_header;then echo "<tr><th>$INPUT" | sed -e 's/:[^,]*\(,\|$\)/<\/th><th>/g' print_header=false fi echo "<tr><td>${INPUT//,/</td><td>}</td></tr>" ; done < Medical.csv ; echo "</table&...


6

There are at least two programs named html2text (1) (2) which do this job.


6

If you are not insisting on sed, the best thing to do this would be lynx. lynx --dump <filename>.html This will output the content of the html file in the format the html code was intending to display. The only condition is that the filename should have a .html or .htm extension.


6

There are plenty of alternatives such as roffit, troff, man2html. There's also perl based online manpage browsers, such as manServer. My favorite is pandoc, though sadly it doesn't seem to support ROFF input by default (though you can probably use it if you need to chain multiple transformation filters together. man2html example: zcat /usr/share/man/man1/...


5

You will have to add Content-Type header to your email to make this happen. echo "<html><b>Hello</b></html>" | mail -a "Content-type: text/html;" -s "Testing" me@example.com will work


5

You need to make it a multipart/mixed message, boundaries and all. ( cat <<EOCAT MIME-Version: 1.0 From: $from To: $to Cc: $cc Subject: TEST email w/ HTML Content-Type: multipart/mixed; boundary=NextPart_0123456789 Content-Transfer-Encoding: 7bit --NextPart_0123456789 Content-Type: text/html EOCAT cat header.html cat html_message_body.html cat footer....


5

You may want to take a look at the Uzbl browser. It's a minimalist web browser based on webkit (the layout engine used by Chrome/Chromium). According to the definition, it's a collection of "web interface tools which adhere to the unix philosophy". It comes in 3 flavors: uzbl-core uzbl-browser uzbl-tabbed The latter 2 are finished products and ...


5

if you only want ... of all <tr>...</tr> do: grep -o '<tr>.*</tr>' HTMLFILE | sed 's/\(<tr>\|<\/tr>\)//g' > NEWFILE for multiline do: cat HTMLFILE | tr "\n" "|" | grep -o '<tr>.*</tr>' | sed 's/\(<tr>\|<\/tr>\)//g' | sed 's/|/\n/g' > NEWFILE check the HTMLFILE first of the char "|" (not usual,...


5

sed and awk are not well suited for this task, you should rather use a proper html parser. For example hxselect from w3.org: <htmlfile hxselect -s '\n' -c 'tr'


5

Try: wget -r -np -k -p http://www.site.com/dir/page.html The args (see man wget) are: r Recurse into links, retrieving those pages too (this has a default max depth of 5, can be set with -l). np Never enter a parent directory (i.e., don't follow a "home" link and mirror the whole site; this will prevent going above ccc in your example). k Convert links ...


5

Pressing this button will only cause the browser to submit a POST request to the server, together with all the values of the according form as payload in the body of the request. So if you want the effect of this click reproduced in a shell script, what you have to do is to build your data in the format it's passed in a POST request, and then submit a POST ...


5

The best strategy would be to use a proper html parser that can spit out the value of all <a> tags. Here, xmlstarlet is specifically an XML parser, and your HTML may not be well-formed XML, but you might get the idea: echo '<html> <a href="000000.jpg" title="image name.jpg" target="_blank">Image name.jpg</a> </html>' | ...


5

You can extract a value in your example with grep and assign it to the variable in the following way $ x=$(wget -0 - 'http://foo/bar.html' | grep -Po '<value.*strValue="\K[[:digit:]]*') $ echo $x 57 Explanation: $(): command substitution grep -P: grep with Perl regexp enable grep -o: grep shows only matched part of the line \K: do not show in the ...


4

You want to use pptHTML: http://www.ma.utexas.edu/restricted-resources/utma-doc/xlHtml/pptHtml.txt For debian based distros: http://packages.debian.org/unstable/utils/ppthtml The C Source for the xlhtml package: http://prdownloads.sf.net/chicago/xlhtml-0.4.9.3.tgz ppthtml is an executable installed through the same package.



Only top voted, non community-wiki answers of a minimum length are eligible