2011-04-01 17 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 
相關問題