对Sed1line中一些命令的理解 四

xiaoxiao2022-10-03  140

 

# 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命令的manIf 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

 

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

转载请注明原文地址: https://www.6miu.com/read-4977992.html

最新回复(0)