对Sed1line中一些命令的理解 四

 

# align all text flush right on a 79-column width 
#右对齐,按79列宽排列所有文本 
sed -e :a -e 's/^.\{1,78\}$/ &/;ta'          # set at 78 plus 1 space

 

t命令的man
If a s/// has done a successful substitution since the last input line was read and since the last t or       T command, then branch to label; if label is omitted, branch to end of script.
一个s///命令成功替换后,那就流程就分支到label出,没成功替换就分支到脚本底部。

-e选项  add the script to the commands to be executed

整体语句的逻辑就是循环把有78个字符替换成空格加它们本身(也就是79列)。

 

 

# center all text in the middle of 79-column width. In method 1, 
# spaces at the beginning of the line are significant, and trailing 
# spaces are appended at the end of the line. In method 2, spaces at 
# the beginning of the line are discarded in centering the line, and 
# no trailing spaces appear at the end of lines. 
#使所有文本居于79列宽的格式中央。在第一种方法中,每一行开头处的空格是 
#很重要的,最后的空格被附在行尾。第二种方法中,一行开头的空格在中心对 
#齐的行中被丢弃,行尾也没有原来结尾处的空格。 
sed -e :a -e 's/^.\{1,77\}$/ & /;ta' # method 1 
sed -e :a -e 's/^.\{1,77\}$/ &/;ta' -e 's/\(*\)1/\1/' # method 2

 

这个语句和上面的类似,不再赘述。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值