需要使用 curl 来 grep 特定的字符串

Ami*_*mit 2 bash awk grep curl

我正在尝试通过 curl 从页面中获取语言代码

我写在下面并工作...

curl -Ls yahoo.com | grep "lang=" | head -1 | cut -d ' ' -f 3 | cut -d"\"" -f 2
Run Code Online (Sandbox Code Playgroud)

但有时代码是不同的

 curl -Ls stick-it.app | grep "lang=" | head -1 | cut -d ' ' -f 3 | cut -d"\"" -f 2
Run Code Online (Sandbox Code Playgroud)

他们写道

<html dir="rtl" lang="he-IL">
Run Code Online (Sandbox Code Playgroud)

我只需要得到 he-IL

如果有其他方法,我将不胜感激......

Ed *_*ton 5

在每个 Unix 机器上的任何 shell 中使用任何 sed:

$ curl -Ls yahoo.com | sed -n 's/^<html.* lang="\([^"]*\).*/\1/p'
en-US
Run Code Online (Sandbox Code Playgroud)