hii, i want to edit she bang line #!/bin/bash line on the top of files in all the files with .sh extension how it done bye scripting . thanks
+1
A:
You can do this using the sed command:
sed -i "1i #!/bin/bash" *.sh
sed
: name of the command-i
: sed option to edit the file inplace1
: line numberi
: to do the insertion before the line number provided before#!/bin/bash
: the shebang to be added*.sh
: to make this work on all .sh files
codaddict
2010-08-06 05:57:05
ca nu please explain what 1i works here
sunil
2010-08-06 05:59:40
its works for existing and newly created sh files is there any option that it impact only on newly created sh files not disturbing the previous ones
sunil
2010-08-06 06:03:37
No, there is not such option for sed. You'll have to use **find** combined with this sed to modify only newly created files.
codaddict
2010-08-06 06:05:18
can u please suggest how to use sed with find "by showing example" i mean is this possible by using ctime options or what
sunil
2010-08-06 06:07:13
A:
find /path -iname "*.sh" -type f -exec sed -i.bak '1i #!/bin/bash' "{}" +;
ghostdog74
2010-08-06 06:24:56