bash - Replacing string in linux using sed/awk based -


i want replace this

#!/usr/bin/env bash 

with this

   #!/bin/bash 

i have tried 2 approaches

approach 1

original_str="#!/usr/bin/env bash" replace_str="#!/bin/bash"  sed s~${original_str}~${replace_str}~ filename 

approach 2

line=`grep -n "/usr/bin" filename` awk nr==${line} {sub("#!/usr/bin/env bash"," #!/bin/bash")} 

but both of them not working.

you cannot use ! inside double quotes in bash otherwise history expansion take place.

you can do:

original_str='/usr/bin/env bash' replace_str='/bin/bash'  sed "s~$original_str~$replace_str~" file #!/bin/bash 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -