Ruby regex gsub a line in a text file

前端 未结 5 613
旧巷少年郎
旧巷少年郎 2020-12-19 20:42

I need to match a line in an inputted text file string and wrap that captured line with a character for example.

For example imagine a text file as such:

<         


        
5条回答
  •  庸人自扰
    2020-12-19 21:26

    Chomp Line Endings

    Your lines probably have newline characters. You need to handle this one way or another. For example, this works fine for me:

    $ ruby -ne 'puts "X#{$_.chomp}X"' /tmp/corpus
    XtestX
    XfooX
    XtestX
    XbarX
    

提交回复
热议问题