root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
$ cut -d / -f 1,2 /etc/passwd
root:x:0:0:root:/root:
bin:x:1:1:bin:/bin:
daemon:x:2:2:daemon:/sbin:
root pts/0 2011-11-16 06:49 (192.168.1.100)
$ who | cut -d / -f 1
root pts
$ ls -l | cut -c 1-10
total 16
drwxr-xr-x
-rw-r--r--
-rw-r--r--
cut -c list [file]
cut -f list [-d delim] [file]
-c list 查询每行的list所表示数据索引的数据 list如:1,10 or 1-10
-d delim 根据delim为定界符,默认为Tab
-f list 设置list的数据段索引,根据-d 返回对应的数据
注:在centos5.4中测试,无法单独的使用-d,一定要和-f一起使用
JOIN的用法
quotas
joe 50
jane 75
herman 80
chris 95
sales
joe 100
jane 200
herman 150
chris 300
#! /bin/sh
#删除注释
sed '/^#/d' quotas | sort > quotas.sorted
sed '/^#/d' sales | sort > sales.sorted
#连接两个文本且打印
join quotas.sorted sales.sorted
#删除缓存文件
rm quotas.sorted sales.sorted
sed的简单用法
#s命令,要求用正则表达式进行寻找,/为分格符,且是默认的分格符,此命令是把baidu替换为google
echo www.baidu.com | sed 's/baidu/google/'
结果:www.google.com
# ; 为分格符,这里是自定义的分格符,紧跟s后的字符,都被认为新的分格符
echo /home/tolstoy | sed 's;\(/home\)/tolstoy;\1/lt;'
# 寻找192.168.0.1开头行,且在192.168.0.1后追加localhost字符串
echo 192.168.0.1:8080 | sed 's/^192.168.0.1/&localhost/'
# 寻找192.168.0.1开头行,且在192.168.0.1替换为localhost字符串
echo 192.168.0.1:8080 | sed 's/^192.168.0.1/localhost/'
cat > template-date
192.168.0.1
what is your name?
what is this?
loveable
I love you
I like you
I need you
^d
# -n与p一起使用,将只打印已被替换的行
sed -n 's/\(love\)able/\1rs/p' template-date
# 打印第1行到第一个以I开头的行的所有行
sed -n '1,/^I/p' template-date
# 从192到I的所有行,每行结束更换为sed test,且打印
sed -n '/192/,/I/s/$/sed test/p' template-date
192.168.0.1sed test
what is your name?sed test
what is this?sed test
loveablesed test
I love yoused test
分享到:
相关推荐
shell脚本自动安装mysql-5.5.30.docx
shell脚本自动安装mysql-5.5.30.pdf
sqlite-shell-win32-x86-3080200.zip sqlite的windows版本
shell脚本学习指南-中文版shell脚本学习指南-中文版shell脚本学习指南-中文版shell脚本学习指南-中文版shell脚本学习指南-中文版shell脚本
藏经阁-Shell 脚本速查手册-29
很全面的Shell编程 脚本专家指南 很合适新手使用
Linux运维-3.Shell编程-11shell基础-101脚本执行方法.avi
Shell脚本编程详解-吐血共享.pdf
Linux shell脚本攻略--数学运算.docx
shell脚本--xnode.sh
Shell-脚本常用命令-文档
Shell脚本培训资料-2015.zip
LINUX与UNIX Shell编程指南16-30.rar
整理了一份Linux shell学习笔记及基本命令合集,包含了LINUX常用操作命令和命令行编辑快捷键、shell基本命令,Linux相关使用配置教程等,需要的朋友可下载试试! shell是一个用C语言编写的程序,它是用户使用Linux的...
NSD-Linux云计算-Shell脚本100例-v0.8.pdf
32.1. 非官方的Shell 脚本风格 33. 杂项 33.1. 交互式和非交互式的shells 和脚本 33.2. Shell 包装 33.3. 测试和比较: 另一种方法 33.4. 递归 33.5. 彩色脚本 33.6. 优化 33.7. 各种小技巧 33.8. 安全话题 33.8.1. ...
shell脚本学习指南,中文清晰带书签, 程序员必备.
上传需要的jar(commons-fileupload-1.2.jar+commons-io-1.3.2.jar)已打包,解压后放入工程lib下。
Linux shell脚本入门教程 - blotemj