1

我有以下问题。我正在解释一个输入文件,现在我遇到了这个问题:我需要翻译%%BLANKxx空格。

因此,无论在输入文件中的哪个位置,我发现例如%%BLANK8,我需要%%BLANK88空格、%%BLANK10空格10等替换。

4

4 回答 4

0

using "%%BLANK" as record seperator , now if any new record that starts with a number replace the number with spaces.

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
于 2011-04-01T12:17:46.540 回答
0
perl -pe 's/%%BLANK(\d+)/" " x $1/e' input_file
于 2011-04-01T11:30:54.347 回答
0

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

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

或红宝石(1.9+)

$ ruby -ne 'print $_.gsub(/%%BLANK(\d+)/){|m|" "*$1.to_i}' file
于 2011-04-01T11:11:09.447 回答
0

您可以在 %%BLANK 标记上拆分您的字符串。之后,您可以读取任何令牌中出现的第一个数字并将其转换为空格。现在,您可以将每个标记连接到一个新字符串中。

于 2011-04-01T10:59:49.957 回答