How can I prepend a string to the beginning of each line in a file?

后端 未结 7 2076
轮回少年
轮回少年 2020-12-08 15:16

I have the following bash code which loops through a text file, line by line .. im trying to prefix the work \'prefix\' to each line but instead am getting this error:

7条回答
  •  死守一世寂寞
    2020-12-08 15:51

    Use sed. Just change the word prefix.

    sed -e 's/^/prefix/' file.ext
    

    If you want to save the output in another file

    sed -e 's/^/prefix/' file.ext > file_new.ext
    

提交回复
热议问题