Using awk to put a header in a text file
问题 I have lots of text files and need to put a header on each one of them depending of the data on each file. This awk command accomplishes the task: awk 'NR==1{first=$1}{sum+=$1;}END{last=$1;print NR,last,"L";}' my_text.file But this prints it on the screen and I want to put this output in the header of each of my file, and saving the modifications with the same file name. Here is what I've tried: for i in *.txt do echo Processing ${i} cat awk 'NR==1{first=$1}{sum+=$1;}END{last=$1;print NR,last