Add text at the end of each line

前端 未结 7 2090
死守一世寂寞
死守一世寂寞 2020-11-28 20:24

I\'m on Linux command line and I have file with

127.0.0.1
128.0.0.0
121.121.33.111

I want

127.0.0.1:80
128.0.0.0:80
121.121         


        
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 20:53

    Concise version of the sed command:

    sed -i s/$/:80/ file.txt
    

    Explanation:

    • sed stream editor
      • -i in-place (edit file in place)
      • s substitution command
      • /replacement_from_reg_exp/replacement_to_text/ statement
      • $ matches the end of line (replacement_from_reg_exp)
      • :80 text you want to add at the end of every line (replacement_to_text)
    • file.txt the file name

提交回复
热议问题