终端下的网络查词小脚本

sh/bash/dash/ksh/zsh等Shell脚本
yihuanlingjian
帖子: 30
注册时间: 2007-10-19 16:53

终端下的网络查词小脚本

#1

帖子 yihuanlingjian » 2009-01-12 20:19

代码: 全选

#!/bin/sh
#
search=compact.php
#
#
# w3m -no-cookie -dump http://dict.cn/${search}?q=$1 > /tmp/tmp.htm
# A=$(sed -n '$=' /tmp/tmp.htm)
# sed $(($A-1)),${A}d /tmp/tmp.htm|sed -n '3,$p'
#
#
w3m -nocookie -dump http://dict.cn/${search}?q=$1 | tac | sed '1,2d' | tac | sed -n '3,$p'
Archlinux下有个dictd,可以在终端下查词,输出结果是全英文的,有时看不懂 :em06 ,于是我就写了这个小脚本,连接dict.cn服务器来查询单词。
....作为小工具,只是 简单地 把文本处理了一下 :em06 ......删除了前两行与后三行 :em02
注释掉的部分是把文件放到tmp下来处理,避免使用tac,可能会省些内存? :em20
保存为dic,chmod +x dic,复制到/usr/local/bin下,执行结果如下: :em01
[simsilver myhost ~]$ dic dictionary
dictionary ['dikʃənəri] 生词本

n. 词典,字典,辞典

例句与用法:

1. Dictionary writers must be skilled in the art of definition.
词书编纂者必须精於给词语下定义的技巧.
2. That is not, properly speaking, a dictionary but a grammar book.
严格地说,那不是一本字典,而是一本语法书。
3. The poet minted several words that cannot be found in any dictionary.
诗人造了几个词典里找不到的词。
4. That dictionary belongs to me.
那本字典是属于我的。
5. This dictionary is available in electronic version.
这部词典有电子版。
6. He is, as it were, a walking dictionary.
他可说是个活字典。
7. A dictionary is an invaluable aid in learning a new language.
在学习一种新语言时,词典是非常有用的工具。
8. Please pass the dictionary to me.
请把字典递给我。
[simsilver myhost ~]$
新加了-no-cookie选项,去除禁用cookie的提示信息
上次由 yihuanlingjian 在 2009-02-10 21:59,总共编辑 3 次。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 终端下的网络查词小脚本

#2

帖子 eexpress » 2009-01-13 9:10

我的sdcv的还配了热键和notify显示
● 鸣学
头像
INUYASHA
帖子: 366
注册时间: 2007-03-16 15:42

Re: 终端下的网络查词小脚本

#3

帖子 INUYASHA » 2009-01-24 20:59

eexpress 写了:我的sdcv的还配了热键和notify显示
共享一下拉
头像
eagle5678
帖子: 1901
注册时间: 2006-07-08 14:07

Re: 终端下的网络查词小脚本

#4

帖子 eagle5678 » 2009-02-01 16:28

INUYASHA 写了:
eexpress 写了:我的sdcv的还配了热键和notify显示
共享一下拉
楼上,ee的东西拿来也不能用的,免了吧,楼上楼上楼上的很好了
yunpengwu
帖子: 294
注册时间: 2007-08-26 10:35
来自: 上海
联系:

Re: 终端下的网络查词小脚本

#5

帖子 yunpengwu » 2009-02-01 23:32

eagle5678 写了:
INUYASHA 写了:
eexpress 写了:我的sdcv的还配了热键和notify显示
共享一下拉
楼上,ee的东西拿来也不能用的,免了吧,楼上楼上楼上的很好了

哈哈,太打击ee了~~
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 终端下的网络查词小脚本

#6

帖子 eexpress » 2009-02-02 10:06

☎ dog sdcv-notify-send.bash
w=`xsel -o`
notify-send -u critical -t 5000 -i '/home/exp/媒体/128软件png/pidgin.png' 'sdcv' "`sdcv -n $w|sed -e '1,4d'`"

我肯定发过的啊。
热键自己设置,调用这脚本就是。
● 鸣学
头像
hellojinjie
帖子: 1150
注册时间: 2007-09-14 21:03
来自: 浙江

Re: 终端下的网络查词小脚本

#7

帖子 hellojinjie » 2009-02-04 17:55

好用,thx
Say hello to everyday!
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

Re: 终端下的网络查词小脚本

#8

帖子 xiooli » 2009-02-04 18:14

代码: 全选

#!/bin/bash

str="`xsel`"
while true ; do
  a="`xsel`"
  if [ "$a" != "$str" ] ; then
    str="$a"
    [ ${#a} -lt 15 ] && word=`w3m -dump -no-cookie http://dict.cn/mini.php?q="$a" | sed -e '$d' -e 's/</ /g' -e 's/>/ /g'`
    gnome-osd-client -f "<message id='word' osd_fake_translucent_bg='off' osd_vposition='top' osd_halignment='right' animations='on' hide_timeout='10000'><span size='15000' foreground='pink'>`echo "$word"`</span></message>"
  fi
  sleep 1
done
头像
anticlockwise
帖子: 2394
注册时间: 2007-03-01 20:46
来自: 湖南长沙

Re: 终端下的网络查词小脚本

#9

帖子 anticlockwise » 2009-02-05 1:00

xiooli 写了:

代码: 全选

#!/bin/bash

str="`xsel`"
while true ; do
  a="`xsel`"
  if [ "$a" != "$str" ] ; then
    str="$a"
    [ ${#a} -lt 15 ] && word=`w3m -dump -no-cookie http://dict.cn/mini.php?q="$a" | sed -e '$d' -e 's/</ /g' -e 's/>/ /g'`
    gnome-osd-client -f "<message id='word' osd_fake_translucent_bg='off' osd_vposition='top' osd_halignment='right' animations='on' hide_timeout='10000'><span size='15000' foreground='pink'>`echo "$word"`</span></message>"
  fi
  sleep 1
done
好东东,顶一个
cmdblock
帖子: 307
注册时间: 2008-12-01 7:52
来自: 蜀山

Re: 终端下的网络查词小脚本

#10

帖子 cmdblock » 2009-02-05 5:33

问楼主,如果我要搜索网易有道的单词
该怎么改?
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

Re: 终端下的网络查词小脚本

#11

帖子 bones7456 » 2009-02-05 8:33

支持~ :em11
关注我的blog: ε==3
头像
lerosua
论坛版主
帖子: 8455
注册时间: 2007-11-29 9:41
联系:

Re: 终端下的网络查词小脚本

#12

帖子 lerosua » 2009-02-05 9:40

一般直接在终端里跑sdcv就行了,还要通知这么麻烦啊?
头像
eagle5678
帖子: 1901
注册时间: 2006-07-08 14:07

Re: 终端下的网络查词小脚本

#13

帖子 eagle5678 » 2009-02-05 15:17

xiooli 写了:

代码: 全选

#!/bin/bash

str="`xsel`"
while true ; do
  a="`xsel`"
  if [ "$a" != "$str" ] ; then
    str="$a"
    [ ${#a} -lt 15 ] && word=`w3m -dump -no-cookie http://dict.cn/mini.php?q="$a" | sed -e '$d' -e 's/</ /g' -e 's/>/ /g'`
    gnome-osd-client -f "<message id='word' osd_fake_translucent_bg='off' osd_vposition='top' osd_halignment='right' animations='on' hide_timeout='10000'><span size='15000' foreground='pink'>`echo "$word"`</span></message>"
  fi
  sleep 1
done
如果copy一大堆东东时,会出现问题
头像
eagle5678
帖子: 1901
注册时间: 2006-07-08 14:07

Re: 终端下的网络查词小脚本

#14

帖子 eagle5678 » 2009-02-05 15:19

yunpengwu 写了:
eagle5678 写了:
INUYASHA 写了:
eexpress 写了:我的sdcv的还配了热键和notify显示
共享一下拉
楼上,ee的东西拿来也不能用的,免了吧,楼上楼上楼上的很好了

哈哈,太打击ee了~~
不是打击ee,ee是长者,要尊重。

我是说,他的东东,都是配置自己用的,没有通用性……还要自己改……
cmdblock
帖子: 307
注册时间: 2008-12-01 7:52
来自: 蜀山

Re: 终端下的网络查词小脚本

#15

帖子 cmdblock » 2009-02-05 18:33

cmdblock 写了:问楼主,如果我要搜索网易有道的单词
该怎么改?
没有哪位大虾指点一下吗?
回复