字符转换指令tr,col,expand

tr -[dsx] seting ...

使用tr替换字符:

[[email protected] ~]$ last | head -n 5 | tr‘[a-z]‘ ‘[A-Z]‘
WHX     PTS/0        192.168.21.1     SUN AUG 27 18:22   STILL LOGGED IN  
REBOOT  SYSTEM BOOT  2.6.32-696.EL6.X SUNAUG 27 18:21 - 00:39  (06:18)   
WHX     PTS/0        192.168.21.1     THU AUG 24 18:37 - 02:54  (08:17)   
WHX     TTY1         :0               THU AUG 24 18:36 - DOWN   (08:18)   
REBOOT  SYSTEM BOOT  2.6.32-696.EL6.X THUAUG 24 18:35 - 02:55  (08:19)   
[[email protected] ~]$ last | head -n 5
whx     pts/0        192.168.21.1     Sun Aug 27 18:22   still logged in  
reboot  system boot  2.6.32-696.el6.x SunAug 27 18:21 - 00:39  (06:18)   
whx     pts/0        192.168.21.1     Thu Aug 24 18:37 - 02:54  (08:17)   
whx     tty1         :0               Thu Aug 24 18:36 - down   (08:18)   
reboot  system boot  2.6.32-696.el6.x ThuAug 24 18:35 - 02:55  (08:19)

添加-d参数删除字符:

[[email protected] ~]$ cat /etc/passwd |head -n5
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[[email protected] ~]$ cat /etc/passwd |head -n5 |tr -d ‘:‘
rootx00root/root/bin/bash
binx11bin/bin/sbin/nologin
daemonx22daemon/sbin/sbin/nologin
admx34adm/var/adm/sbin/nologin
lpx47lp/var/spool/lpd/sbin/nologin

添加-s参数去除重复字符:

[[email protected] ~]$ echo ‘thissss   issss aaaa test‘|tr -s ‘sa‘
this  is a  test

col常用于将man page转存为纯文本文件以方便查阅。

col -x 将tab替换成对等的空格键

[[email protected] ~]$ cat  /etc/man.config | tail -10 | col -x |cat -A|tail -10
#$
# Enable/disable makewhatis database cronupdates.$
# If MAKEWHATISDBUPDATES variable isuncommented$
# and set to n or N, cron scripts$
# /etc/cron.daily/makewhatis.cron$
# /etc/cron.weekly/makewhatis.cron$
# will not update makewhatis database.$
# Otherwise the database will be updated.$
#$
#MAKEWHATISDBUPDATES    n$
[[email protected] ~]$ cat  /etc/man.config | tail -10 | cat -A
#$
# Enable/disable makewhatis database cronupdates.$
# If MAKEWHATISDBUPDATES variable isuncommented$
# and set to n or N, cron scripts $
# /etc/cron.daily/makewhatis.cron$
# /etc/cron.weekly/makewhatis.cron$
# will not update makewhatis database.$
# Otherwise the database will be updated.$
# $
#MAKEWHATISDBUPDATES^In$

expand转换指令:

expand  [-t] file

使用-t参数设置使用6个空格键代替tab键(默认使用8个空格键代替tab键)

[[email protected] ~]$ grep ‘^MANPATH‘/etc/man.config |head -n 3 | expand -t 6 |cat -A
MANPATH    /usr/man$
MANPATH    /usr/share/man$
MANPATH    /usr/local/man$
[[email protected] ~]$ grep ‘^MANPATH‘/etc/man.config |head -n 3 | cat -A
MANPATH^I/usr/man$
MANPATH^I/usr/share/man$
MANPATH^I/usr/local/man$
时间: 2024-08-19 08:29:27

字符转换指令tr,col,expand的相关文章

linux字符转换指令

1.tr  [-ds] SET1 -:可以用来删除一段讯息中的文字,或者进行文字信息转换,参数: 1)-d:删除信息中SET1这个字符串 2)-s:取代重复的字符串 不加任何参数,分别需要两个字符串或正则表达式,执行替换操作,分别对应源字符串和替换后字符串 2.col  [-xfb][-l 缓冲区列表]:过滤控制字符,参数, 1)-x:将tab键转换成对等的空格键(经测试,该指令未发现其效果) 2)-b:在文字内有反斜杠时,仅保留反斜杠最后接的那个字符,即将特表组合键的符号去掉 3.join  

【Linux】字符转换命令tr

tr (traslate的缩写)可以用来删除一段信息当中的文字,或者是进行文字信息的替换! [[email protected] ~]# tr [-ds] SET1 ... 选项与参数: -d :删除信息当中的 SET1 这个字符串: -s :取代掉重复的字符! 范例一:将 last 输出的信息中,所有的小写变成大写字符: [[email protected] ~]# last | tr '[a-z]' '[A-Z]' # 事实上,没有加上单引号也是可以运行的,如:『 last | tr [a-

Linux管线命令 - cut,grep,sort,uniq,wc,tee,tr,col,join,paste,expand,split,xargs

在每个管线后面接的第一个数据必定是『命令』喔!而且这个命令必须要能够接受 standard input 的数据才行,这样的命令才可以是为『管线命令』,例如 less, more, head, tail 等都是可以接受 standard input 的管线命令啦.至于例如 ls, cp, mv 等就不是管线命令了!因为 ls, cp, mv 并不会接受来自 stdin 的数据. 也就是说,管线命令主要有两个比较需要注意的地方: 管线命令仅会处理 standard output,对于 standar

字符转换(2,8,10,16进制,ASCII码)

罗列了一些用到的,各进制 以及 ASCII 间的转换,记录备忘 一,先说说 2,8,10 ,16 各进制之间的转化 System.Convert类中提供了较为全面的各种类型.数值之间的转换功能: 几个比较常用的方法  1,Convert.ToInt32(string value, int fromBase)  :将字符串转换为数字(如2进制0010>也就是2^1=2)  fromBase: 顾名思义参数的进制(2,,8,10,16)     2,Convert.Tostring(int valu

java GBK字符转换成为UTF-8编码字符

import java.util.HashMap; import java.util.Map; /** * 创建日期: 2014-04-18 10:36:25 * 作者: 黄飞 * mail:[email protected] [email protected] * ©版权归作者所有 * */ public class ConverFromGBKToUTF8 { public static void main(String[] args) { try { ConverFromGBKToUTF8

*数组-01. 字符转换

1 /* 2 * Main.c 3 * E1-数组-01. 字符转换 4 * Created on: 2014年8月20日 5 * Author: Boomkeeper 6 ******部分通过********** 7 */ 8 9 #include <stdio.h> 10 11 int main(void) { 12 13 char str[80] = { -1 }; 14 15 gets(str); 16 17 int i; 18 for (i = 0; i < 80; i++)

发送邮件字符转换

//將html轉為text public string HtmlToText(string strContent) { strContent = strContent.Replace("&amp", "&"); strContent = strContent.Replace("''", "'"); strContent = strContent.Replace("&lt", &quo

IO-04字节-字符转换流

掌握OutputStreamWriter和InputStreamReader的作用. 在整个IO包中,实际上就是分为字节流和字符流,但除了这两个流之外,还存在一组字节-字符流转换类. OutputStreamWriter:是Writer的子类,将输出的字符流编程字节流,既:将一个字符流的输出对象变成字节流输出对象. InputStreamReader:是Reader的子类,将输入的字节流变成字符流.既:将一个字节流的输入对象变成字符流的输入对象. 字符流转换成字节流的代码: package li

HDOJ/HDU 2140 Michael Scofield&#39;s letter(字符转换~)

Problem Description I believe many people are the fans of prison break. How clever Michael is!! In order that the message won't be found by FBI easily, he usually send code letters to Sara by a paper crane. Hence, the paper crane is Michael in the he