There is a project in which there are a lot of files, how can you add the same line to each project file? Handles do not want to do)

  • Clarify the question. Where to insert - at the beginning of the file, at the end of the file, after a certain line? Need to insert into all files or into files of a certain type, for example, project service files? (You can specify which project) - AK
  • It is necessary to insert the extension files js and jsx at the beginning of the file. - Alex

1 answer 1

you can use, for example, the sed program:

$ sed -i '1s/^/эта строка будет первой\n/' *.js *.jsx 

do not forget to backup files before executing it.

  • Thanks for the hint, implemented the script in this way: find app -type f -name "*.jsx" | while read FILENAME; do gsed -i '1s/^/import settings from "settings\/settings";\n/' $FILENAME echo "$FILENAME" done find app -type f -name "*.js" | while read FILENAME; do gsed -i '1s/^/import settings from "settings\/settings";\n/' $FILENAME echo "$FILENAME" done find app -type f -name "*.jsx" | while read FILENAME; do gsed -i '1s/^/import settings from "settings\/settings";\n/' $FILENAME echo "$FILENAME" done find app -type f -name "*.js" | while read FILENAME; do gsed -i '1s/^/import settings from "settings\/settings";\n/' $FILENAME echo "$FILENAME" done find app -type f -name "*.jsx" | while read FILENAME; do gsed -i '1s/^/import settings from "settings\/settings";\n/' $FILENAME echo "$FILENAME" done find app -type f -name "*.js" | while read FILENAME; do gsed -i '1s/^/import settings from "settings\/settings";\n/' $FILENAME echo "$FILENAME" done The script recursively iterates through all the files in the app directory, selects only .js and .jsx files and inserts at the beginning of these files line. Can you tell me how can this be implemented more gracefully? - Alex