本文共 816 字,大约阅读时间需要 2 分钟。
tr替换:
tr 替换字符:被替换的字符与替换的字符数必须是相等的用法:tr 旧字符 新字符cat > a.txt <<EOF
root:1:0:binbin:2:200:bashjim:10:300:bashtom:102:10:bashbin:2:200:bashEOFcat a.txt | tr 20 89 将cat a.txt中的结果中的20替换成89
root:1:9:binbin:8:899:bashjim:19:399:bashtom:198:19:bashbin:8:899:bashcat a.txt | tr 'a-z' 'A-Z' 在替换的时候是一一对应的替换
ROOT:1:0:BINBIN:2:200:BASHJIM:10:300:BASHTOM:102:10:BASHBIN:2:200:BASHcat a.txt | tr 0-4 5-9
root:6:5:binbin:7:755:bashjim:65:855:bashtom:657:65:bashbin:7:755:bash\n 换行符
cat a.txt | tr "\n" "+" 将换行符换成+号root:1:0:bin+bin:2:200:bash+jim:10:300:bash+tom:102:10:bash+bin:2:200:bash+cat a.txt | tr -s "o0" 用-s把连续重复的字符替换成一个字符
rot:1:0:binbin:2:20:bashjim:10:30:bashtom:102:10:bashbin:2:20:bashecho >> a.txt 在a.txt文件中追加空白行,请执行3次
cat a.txt | tr -s "\n" 去掉空白行
转载于:https://blog.51cto.com/13553337/2088278