linux中的join、paste、split、tr命令
来源:互联网 发布:鲈鱼脍 知乎 编辑:程序博客网 时间:2024/04/30 18:55
join:join用来将来自两个分类文本文件的行连在一起。文本文件中的域通常由空格或 tab键分隔,但如果愿意,可以指定其他的域分隔符。一些 系统要求使用 join时文件域要少于 20,为公平起见,如果域大于 20,应使用 DBMS系统。让我们看看它的可用选项列表:an n 为一数字,用于连接时从文件 n中显示不匹配行。例如, -a1显示第一个文件的不匹 配行, -a2为从第二个文件中显示不匹配行。o n.m n 为文件号, m为域号。 1.3表示只显示文件 1第三域,每个 n,m必须用逗号分隔, 如1.3,2.1。j n m n为文件号, m为域号。使用其他域做连接域。t 域分隔符。用来设置非空格或 tab键的域分隔符。例如,指定冒号做域分隔符 -t:。
命令行实例:[root@redhat script]#cat names.txt M.Golls 12 Hidd RdP.Heller The AcreP.Willey 132 The GroveT.Norms 84 Connaught RdK.Fletch 23 Woodlea[root@redhat script]#[root@redhat script]#cat town.txt M.Golls Norwich NRDP.Willey Galashiels GDDT.Norms Brandon BSLK.Fletch Mildenhall MAF[root@redhat script]#[root@redhat script]#join names.txt town.txt M.Golls 12 Hidd Rd Norwich NRDP.Willey 132 The Grove Galashiels GDDT.Norms 84 Connaught Rd Brandon BSLK.Fletch 23 Woodlea Mildenhall MAF的的
paste:paste将按行将不同文件行信息放在一行。缺省情况下, paste连接时,用空格或 tab键分隔 新行中不同文本,除非指定 -d选项,它将成为域分隔符。paste格式为;paste -d -s -file1 file2选项含义如下:-d 指定不同于空格或 tab键的域分隔符。例如用 @分隔域,使用 -d@。-s 将每个文件合并成行而不是按行粘贴。- 使用标准输入。例如 ls -l |paste ,意即只在一列上显示输出。命令行实例:[root@redhat script]#cut -d: -f1 pers > pas1[root@redhat script]#cat pas1 P.JonesS.RoundL.Clip[root@redhat script]#[root@redhat script]#cut -d: -f3 pers > pas2[root@redhat script]#cat pas2ID897ID666ID982[root@redhat script]#[root@redhat script]#paste pas1 pas2P.JonesID897S.RoundID666L.ClipID982
split:split用来将大文件分割成小文件。有时文件越来越大,传送这些文件时,首先将其分割可 能更容易。使用 vi或其他工具诸如 sort时,如果文件对于工作缓冲区太大,也会存在一些问题。 因此有时没有选择余地,必须将文件分割成小的碎片。split命令一般格式:split -output_file-size input-filename output-filename这里output-file-size指的是文本文件被分割的行数。 split查看文件时, output-file-size选项 指定将文件按每个最多 1000行分割。如果有个文件有 2800行,那么将分割成 3个文件,分别有1000、1000、800行。每个文件格式为 x[aa]到x[zz],x为文件名首字母, [aa]、[zz]为文件名剩 余部分顺序字符组合。[root@redhat split]#cat split1 this is line1this is line2this is line3this is line4this is line5this is line6[root@redhat split]#split -2 split1 [root@redhat split]#ll总用量 16-rwxrwxrwx 1 root root 84 2011/12/07 07:04:20 split1-rw-r--r-- 1 root root 28 2011/12/07 07:06:46 xaa-rw-r--r-- 1 root root 28 2011/12/07 07:06:46 xab-rw-r--r-- 1 root root 28 2011/12/07 07:06:46 xac[root@redhat split]#[root@redhat split]#cat xaa && echo ======= && cat xab && echo ======= && cat xacthis is line1this is line2=======this is line3this is line4=======this is line5this is line6
tr:tr用来从标准输入中通过替换或删除操作进行字符转换。 tr主要用于删除文件中控制字符 或进行字符转换。使用 tr时要转换两个字符串:字符串 1用于查询,字符串2用于处理各种转换。 tr刚执行时,字符串 1中的字符被映射到字符串 2中的字符,然后转换操作开始。指定字符串 1或字符串 2的内容时,只能使用单字符或字符串范围。命令格式为:tr-c-d-s["string1_to_translate_from"]["string2_to_t riannpsulta_te_to" ]file这里:-c 用字符串 1中字符集的补集替换此字符集,要求字符集为 ASCII。-d 删除字符串 1中所有输入字符。-s 删除所有重复出现字符序列,只保留第一个;即将重复出现字符串压缩为一个字符串。Input-file是转换文件名。虽然可以使用其他格式输入,但这种格式最常用。字符范围:[a-z]a-z内的字符组成的字符串。 [A-Z] A-Z内的字符组成的字符串。 [0-9]数字串。/octal 一个三位的八进制数,对应有效的 ASCII字符。[O*n] 表示字符 O重复出现指定次数 n。因此 [O*2]匹配OO的字符串。 大部分 tr变种支持字符类和速记控制字符。字符类格式为 [:class],包含数字、希腊字母、空行、小写、大写、 cntrl键、空格、点记符、图形等等。tr中特定控制字符的不同表达方式:速记符含义八进制方式\aCtrl-G 铃声 \007\bCtrl-H 退格符 \010\fCtrl-L 走行换页\014\nCtrl-J 新行 \012\rCtrl-M 回车 \015\t Ctrl-I tab键 \011\vCtrl-X \030命令行实例:(无转换控制字符的例子)[root@redhat script]#cat oops.txt And the cowwwwws went homeeeeeeeOr did theyyyy[root@redhat script]#tr -s "[a-z]" < oops.txt And the cows went homeOr did they[root@redhat script]#[root@redhat script]#tr -s "[A-Z]" < oops.txt And the cowwwwws went homeeeeeeeOr did theyyyy[root@redhat script]#[root@redhat script]#cat oops.txt | tr -s "[a-z]" And the cows went homeOr did they[root@redhat script]#[root@redhat script]#cat oops.txt And the cowwwwws went homeeeeeeeOr did theyyyyssssssssssssssssssssssssssssssdd11111111111111111111111111[root@redhat script]#[root@redhat script]#tr -s ["\n"] < oops.txt And the cowwwwws went homeeeeeeeOr did theyyyyssssssssssssssssssssssssssssssdd11111111111111111111111111[root@redhat script]#echo "May Day,May Day,Going Down..." | tr "[:upper:]" "[:lower:]"may day,may day,going down...[root@redhat script]#[root@redhat script]#echo "monday123" | tr -c "[a-z]" "[\012*]"mondayYou have new mail in /var/spool/mail/root[root@redhat script]#[root@redhat script]#echo "monday12" | tr -c "[a-z]" "[\012*]"monday[root@redhat script]#echo "monday1" | tr -c "[a-z]" "[\012*]"monday[root@redhat script]#echo "monday" | tr -c "[a-z]" "[\012*]"monday[root@redhat script]#[root@redhat script]#echo "0000 hdisk5" | tr "[0*4]" "-"---- hdisk5
原文:http://www.tuicool.com/articles/3AZf2q
0 0
- linux中的join、paste、split、tr命令
- Linux新手生存笔记[7]——重点命令4-tr&join&cut&paste&split
- Linux新手生存笔记[7]——重点命令4-tr&join&cut&paste&split
- Linux管线命令 - cut,grep,sort,uniq,wc,tee,tr,col,join,paste,expand,split,xargs
- 《Linux命令、编辑器与Shell编程》读书笔记4.3-其他数据文件处理命令(tr,sort,cut,paste,join,uniq,split)
- linux命令之字符转换命令:tr, col, join, paste
- linux---tr,col,join,paste,expand 字符转换命令
- 第7课重点命令4-tr&join&cut&paste&split
- linux paste join命令
- Linux基本指令之sort、uniq、join、cut、paste、split、tr
- 【转帖】Linux Cut 命令 与 Paste命令&Join命令&tr命令
- sort,uniq,join,cut,paste,split,tr学习
- Linux命令(11)——字符转换命令:tr、col、join、paste、expand
- shell 知识点补充(2)-重定向/ ; , &&, ||/管线命令/grep/sort/ uniq/wc/tee/tr/col/join/paste/expand/split/-
- linux命令join与paste
- Linux下五个字符转换命令:tr,col,join,paste,expand
- 字符串转换命令:tr,col,join,paste,expand
- Shell文本处理 (2). cut、sort、wc、uniq、tr、 join、paste、 split、xargs
- 【more effective c++读书笔记】【第4章】效率(3)
- Android按键事件处理流程 -- KeyEvent
- cocos2dx tolua c++
- poj3076(16*16数独)
- spring MVC(十)---spring MVC整合mybatis
- linux中的join、paste、split、tr命令
- Android 小贴士
- 360个人软件发布所遭遇的情况
- 威胁我?
- 工作中遇到的问题3
- IIS命令行启动
- Android 国际化,资源文件
- Android Support ;v4、v7、v13的区别
- MySQL的create table as 与 like区别