How can I add a string to the beginning of each file in a folder in bash?

前端 未结 9 894
天命终不由人
天命终不由人 2021-01-01 17:04

I want to be able to prepend a string to the beginning of each text file in a folder. How can I do this using bash on Linux?

9条回答
  •  无人及你
    2021-01-01 17:39

    You can do it like this without a loop and cat

    sed -i '1i whatever' *
    

    if you want to back up your files, use -i.bak

    Or using awk

    awk 'FNR==1{$0="whatever\n"$0;}{print $0>FILENAME}' *
    

提交回复
热议问题