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

后端 未结 7 2056
轮回少年
轮回少年 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 16:05

    You don't need sed, just concatenate the strings in the echo command

    while IFS= read -r line; do
        echo "prefix$line"
    done < filename
    

    Your loop iterates over each word in the file:

    for line in `cat file`; ...
    

提交回复
热议问题