find /home/tolstoy -typed d -print |寻找所有目录
sed 's; /home/tolstoy/;/home/lt/;' |修改名称这里用分号作为界定符
sed 's/^/mkdir /' |插入 mkdir 命令
sh -X 以shell 命令跟踪模式执行
上述脚本是将/home/tolstoy 目录结构建立一份副本在/home/lt 下
~$ echo tolstoy reads well. tolstoy writes well. > example.txt
siat@siat-HP:~$ sed 's/tolstoy/camus/' < example.txt
camus reads well. tolstoy writes well.
siat@siat-HP:~$ sed 's/tolstoy/camus/g' < example.txt
camus reads well. camus writes well.
如果没有设置g (global) 即替代文本取代正则表达式中每个匹配的‘
sed 's/tolstoy/camus/2' < example.txt
tolstoy reads well. camus writes well.
只匹配第二个
echo abc | sed 's/b*/1/' 替代第一个匹配成功的 包括NULL字符
1abc
siat@siat-HP:~$ echo abc | sed 's/b*/1/g' 替代所有匹配成功的
1a1c1
排序
siat@siat-HP:~$ sort -t_ -k1,1 -k2,2 << EOF
> one_two
> one_two_three
> one_two_four
> one_two_five
> EOF
one_two
one_two_five
one_two_four
one_two_three
计算行数字数及字符数
echo this si a test the hiohoh hiooi hioo | wc
1 8 37
行数 字数 字符数
echo this si a test the hiohoh hiooi hioo | wc -c
37
siat@siat-HP:~$ echo this si a test the hiohoh hiooi hioo | wc -l
1
siat@siat-HP:~$ echo this si a test the hiohoh hiooi hioo | wc -w
8