-1

I would like to add login credentials

user: XXX ; pass:YYYY

as text line in all files of a given directory (as a string at the start of each file).

Also i would like to add this only in files with a certain extension .kkk

How can I do that? Thanks

AdminBee
  • 21,637
  • 21
  • 47
  • 71
ECII
  • 101
  • 2
  • 2
    Does this answer your question? [How to insert text before the first line of a file?](https://unix.stackexchange.com/questions/99350/how-to-insert-text-before-the-first-line-of-a-file) – AdminBee Nov 19 '20 at 09:48

1 Answers1

1

You can use sed or awk for that:

  • sed:
    sed '1i\user: XXX ; pass:YYY' *.kkk
    
  • awk:
    awk 'BEGIN{print "user: XXX ; pass:YYY"}1' *.kkk
    

In order to edit the files in-place, use the -i option for sed. For awk this only works since GNU awk version 4.1, when using the -i inplace option.

Update: This question has already answers here and here (and possibly others).

AdminBee
  • 21,637
  • 21
  • 47
  • 71