You are not logged in.
Hi,
I want to add a line of text to several files.
I can locate the files I want to add the text line to using this command: grep -lr "/bin/sh" .
This generates the list of files I need to modify.
Now, I want to add a string - LANG=he_IL - to all those files, AFTER the line #!/bin/sh (this line always comes first in every file).
Can anyone suggest a simple bash script to do so?
Thanks a lot,
Fiod
Offline
Read up on sed.
End of line sign is '$'. So that would become:
sed 's/$/LANG=he_IL/' files
/edit
Oh and to skip the first line there's a rule too, but you could also use something like:
sed '\@#\!/bin/sh@!s@$@LANG=he_IL@' files
please first test this code on an example in case I forgot something!
Last edited by ibendiben (2009-01-23 11:49:13)
Offline
sed -i '2i LANG=he_IL' $(grep -lr .)
Offline
sed -i '2i LANG=he_IL' $(grep -lr .)
Worked like a charm!
Thanks..
Offline