2011-04-01 52 views

回答

0

您可以%%空白标签分割你的字符串。 之后,您可以阅读任何令牌中的第一个数字并将其转换为空格。 现在,您可以在新字符串中连接每个标记。

0

试试这个。我还没有彻底测试

$ awk '/BLANK/{ match($0,/%%BLANK([0-9]+)/,a);s=sprintf("%"a[1]"s","") ; gsub(a[0],s)}1' file 

或Ruby(1.9+)使用

$ ruby -ne 'print $_.gsub(/%%BLANK(\d+)/){|m|" "*$1.to_i}' file 
+0

这一个也适用! – 2011-04-01 11:49:42

0
perl -pe 's/%%BLANK(\d+)/" " x $1/e' input_file 
+0

作为一个魅力..谢谢! – 2011-04-01 11:50:07

0

“%% BLANK” 作为记录分隔符,现在如果以数字开头的新记录替换数字与空格。

awk 'BEGIN {RS="%%BLANK";ORS=""}{MatchFound=match($0,"^[0-9]+",Matched_string);if(MatchFound){sub(Matched_string[0],"",$0);for (i=0;i<Matched_string[0];i++){$0=" "$0};print $0}else{print $0}}' InputFile.txt 
相关问题