Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品与服务 | Email

第 22 章 Utility Programs

目录

22.1. ed, red - text editor
22.2. vim
22.2.1. 查找与替换
22.2.2. 批处理
22.2.2.1. vi 批处理
22.2.3. line()
22.3. CURL - transfer a URL
22.3.1. 基本用法
22.3.2. data
22.3.3. connect-timeout
22.3.4. compressed
22.3.5. vhosts
22.3.6. 输出格式定义
22.3.7. -A/--user-agent <agent string>
22.3.8. referer
22.3.9. -v
22.3.10. -o/--output <file>
22.3.11. -H/--header <line> Custom header to pass to server (H)
22.3.11.1. Last-Modified / If-Modified-Since
22.3.11.2. ETag / If-None-Match
22.3.11.3. Accept-Encoding:gzip,defalte
22.3.11.4. HOST
22.3.11.5. HTTP 认证
22.3.12. curl-config
22.3.13. FAQ
22.4. awk
22.4.1. 处理列
22.4.2. printf
22.4.3. Pattern(字符匹配)
22.4.3.1. Pattern, Pattern
22.4.4. Built-in Variables
22.4.4.1. NR
22.4.4.2. NF
22.4.5. Built-in Functions
22.4.5.1. length
22.4.6. 过滤相同的行
22.5. sed
22.5.1. 查找与替换
22.5.1.1. 正则
22.5.1.2. delete
22.5.1.3. aaa="bbb" 提取bbb
22.5.1.4. 首字母大写
22.5.2. 编辑文件
22.5.3. 内容打印
22.5.4. 编辑操作
22.6. expect
22.6.1. 模拟登录 telnet 获取Cisco配置
22.6.2. 模拟登录 ssh
22.6.3. SCP
22.7. expect-lite - quick and easy command line automation tool
22.8. sshpass - noninteractive ssh password provider
22.9. Klish - Kommand Line Interface Shell (the fork of clish project)
22.9.1. 安装Klish
22.9.2. 为用户指定clish作为默认Shell
22.9.3. FAQ
22.9.3.1. clish/shell/shell_expat.c:36:19: fatal error: expat.h: No such file or directory
22.10. Limited command Shell (lshell)
22.11. wget - retrieves files from the web
22.11.1. Logging and input file
22.11.1.1. -i, --input-file=FILE download URLs found in local or external FILE.
22.11.2. HTTP options
22.11.2.1. --post-data=STRING use the POST method; send STRING as the data.
22.11.3. Recursive download
22.11.3.1. -r, --recursive specify recursive download.
22.11.3.2. -m, --mirror shortcut for -N -r -l inf --no-remove-listing.
22.11.4. --no-passive-ftp disable the "passive" transfer mode.
22.12. TUI
22.12.1. screen - screen manager with VT100/ANSI terminal emulation
22.12.2. tmux — terminal multiplexer
22.12.3. byobu - wrapper script for seeding a user's byobu configuration and launching a text based window manager (either screen or tmux)
22.12.4. htop - interactive process viewer
22.12.5. elinks
22.12.6. chat
22.13. parallel - build and execute shell command lines from standard input in parallel

22.1. ed, red - text editor

行寻址

.	此选项对当前行寻址(缺省地址)。
number	此选项对第 number 行寻址。可以按逗号分隔的范围 (first,last) 对行寻址。0 代表缓冲区的开头(第一行之前)。
-number	此选项对当前行之前的第 number 行寻址。如果没有 number,则减号对紧跟在当前行之前的行寻址。
+number	此选项对当前行之后的第 number 行寻址。如果没有 number,则加号对紧跟在当前行之后的行寻址。
$	此选项对最后一行寻址。
,	此选项对第一至最后一行寻址,包括第一行和最后一行(与 1,$ 相同)。
;	此选项对当前行至最后一行寻址。
/pattern/	此选项对下一个包含与 pattern 匹配的文本的行寻址。
?pattern?	此选项对上一个包含与 pattern 匹配的文本的行寻址。	
		

命令描述

a	此命令在指定的地址之后追加文本。
c	此命令将指定的地址更改为给定的文本。
d	此命令删除指定地址处的行。
i	此命令在指定的地址之前插入文本。
q	此命令在将缓冲区保存到磁盘后终止程序并退出。
r file	此命令读取 filespec 的内容并将其插入指定的地址之后。
s/pattern/replacement/	此命令将匹配 pattern 的文本替换为指定地址中的 replacement 文本。
w file	此命令将指定的地址写到 file。如果没有 address,则此命令缺省使用整个缓冲区。
		

实例,删除passwd中的neo用户

		
ed -s passwd <<EOF
/neo/
d
wq
EOF
		
		
		
ed -s mfsmetalogger.cfg <<EOF
,s/^# //
wq
EOF		
		
		

删除尾随空格

		
$ cat -vet input.txt

This line has trailing blanks.    $
This line does not.$

$ (echo ',s/ *$//'; echo 'wq') | ed -s input.txt

$ cat -vet input.txt

This line has trailing blanks.$
This line does not.$
				
		
comments powered by Disqus