linux简单的文本合并以及tab键转换
2016-04-22 17:25
465 查看
一、常用的文本处理命令
1.tr命令
可以删除一段文本信息中的某些文字或进行转换。
-d :删除和设置中做匹配的字符
-s :去除设置中指定的在输入文本中连续并重复的字符。
eg:echo 'hello myfriend' | tr -d 'olhi'
输出为:e my frend
eg:echo 'hello' | tr -s'l'
输出为:helo
2.col命令
用于tab键和空格之间的转换
-x:将Tab键换成空格键
-h:将空格键换为Tab键
eg:cat -A/etc/protocols
查看到文件中有许多^I字符
eg:cat /etc/protocols |col -x | cat -A
查看文件发现^I被换成了空格
3.join命令
将两个文件包含的相同内容合并在一起
-t:指定分隔符,默认为空格
-i:忽略大小写差异
-1:指定第一个文件要用字段对比,默认对比第一个字段
-2:指定第二个文件要用字段对比。
eg: echo '1 hello' > file1
eg: echo '1 hi' >file2
eg: joinfile1 file2
输出结果为:1 hello hi
eg:sudo join -t ':'/etc/passwd /etc/shadow
表示指定分隔符为‘:’
eg: sudo join -t ':' -1 4 /etc/passwd -2 3 /etc/group
表示经第一个文件中的第四个字符段和第二个文件中的第三个字符段对比合并
4.paste命令
简单将各个文件合并
-d:指定合并的分隔符,默认为Tab
-s:不合并到一行,每个文件为一行
eg:echo hello >file1
eg:echo hi >file2
eg:echo joyful >file3
eg:paste -d ':' file1file2 file3
输出结果形式为:
hello:hi:joyful
eg:paste -s file1 file2file3
输出结果形式为:
hello
hi
joyful
1.tr命令
可以删除一段文本信息中的某些文字或进行转换。
-d :删除和设置中做匹配的字符
-s :去除设置中指定的在输入文本中连续并重复的字符。
eg:echo 'hello myfriend' | tr -d 'olhi'
输出为:e my frend
eg:echo 'hello' | tr -s'l'
输出为:helo
2.col命令
用于tab键和空格之间的转换
-x:将Tab键换成空格键
-h:将空格键换为Tab键
eg:cat -A/etc/protocols
查看到文件中有许多^I字符
eg:cat /etc/protocols |col -x | cat -A
查看文件发现^I被换成了空格
3.join命令
将两个文件包含的相同内容合并在一起
-t:指定分隔符,默认为空格
-i:忽略大小写差异
-1:指定第一个文件要用字段对比,默认对比第一个字段
-2:指定第二个文件要用字段对比。
eg: echo '1 hello' > file1
eg: echo '1 hi' >file2
eg: joinfile1 file2
输出结果为:1 hello hi
eg:sudo join -t ':'/etc/passwd /etc/shadow
表示指定分隔符为‘:’
eg: sudo join -t ':' -1 4 /etc/passwd -2 3 /etc/group
表示经第一个文件中的第四个字符段和第二个文件中的第三个字符段对比合并
4.paste命令
简单将各个文件合并
-d:指定合并的分隔符,默认为Tab
-s:不合并到一行,每个文件为一行
eg:echo hello >file1
eg:echo hi >file2
eg:echo joyful >file3
eg:paste -d ':' file1file2 file3
输出结果形式为:
hello:hi:joyful
eg:paste -s file1 file2file3
输出结果形式为:
hello
hi
joyful
相关文章推荐
- linux 批量修改文件内容
- Linux Ramdisk mini-HOWTO
- linux yum下载RPM包后再安装LAMP环境
- Linux信号处理函数
- linux命令中,执行一个程序,后面加上&, 代表的意思是什么?
- linux DMA原理
- 调用程序继承fd和监听端口的问题
- /usr/bin/ld: client: hidden symbol `__dso_handle' in /usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o is
- 《linux实例大全》学习笔记1
- 一.Linux系统:用户及文件权限管理
- CentOS6.6-64下rpm方式mysql-5.7.12安装实录
- python脚本执行linux命令
- Heartbeat (Linux-HA工程的一个组件)
- Centos7 nfs 共享 mount远程目录
- # sed 查找匹配行
- Linux(Ubuntu) 新手安装JDK,一步一步实现(详解)
- bitbake linux-name 执行各个task的过程
- Linux 技巧:让进程在后台可靠运行的几种方法
- Linux中的动态库和静态库(.a/.la/.so/.o)
- CentOS6网卡静态IP设置