使用grep提取html文件的标题 [英] Extract Title of a html file using grep

查看:19
本文介绍了使用grep提取html文件的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cat 1.html | grep "<title>" > title.txt  

此 grep 语句不起作用.

This grep statement is not working.

请说出使用 grep 或 sed 获取页面标题的最佳方法.

Please tell the best way to grab the title of a page using grep or sed.

谢谢.

推荐答案

你可以使用 awk.这甚至适用于多行

you can use awk. This works even for multiline

$ cat file

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

    <title>Extract Title of a html file

using grep - Stack Overflow</title>
    <link rel="stylesheet" type="text/css" href="http://sstatic.net/stackoverflow/all.css?v=9ea1a272f146">

$ awk -vRS="</title>" '/<title>/{gsub(/.*<title>|
+/,"");print;exit}' file
Extract Title of a html file using grep - Stack Overflow

这篇关于使用grep提取html文件的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆