开发者

replace blank column with word

I have a text file some of the record is blank and I want replace that blank space with the word N/A or null

ex-

field-A  field-b  field-c   field-d   field-e  field-f  field-g  field-h   field-i
1           2       3          4      5           6     7           8          9 

1                   3          4      5           6      7          8          9

            2       3          4      5           6      7          8          9

1                         开发者_开发百科      4     5           6      7          8          9

result expect

field-A  field-b  field-c   field-d   field-e  field-f  field-g  field-h   field-i
1           2       3          4      5           6     7           8          9 

1          N/A      3          4      5           6      7          8          9

N/A         2       3          4      5           6      7          8          9

1          N/A     N/A         4     5            6      7          8          9


perl -pe 's/  / x / while /  /' <<END
1 2 3 4 5 6 7 8 9
1  3 4 5 6 7 8 9
  2 3 4 5 6 7 8 9
1   4 5 6 7 8 9
END

produces

1 2 3 4 5 6 7 8 9
1 x 3 4 5 6 7 8 9
 x 2 3 4 5 6 7 8 9
1 x x 4 5 6 7 8 9


If it's a space character I'd look for the character code or a blank space.

In C# assuming your variable was mystr it would be something like:

myStr = myStr.Replace(" ", "N/A");

You can also look for the character value, depending on the language you're using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜