Team,
I want to change below parameter in all the files in a directory,
Check for HOSTNAME=`hostname`
Change to HOSTNAME=localhost
And I tried below but, its not working
find /tmp -type f -exec sed 's/"HOSTNAME\=\`hostname\`"/"HOSTNAME\=localhost/g'"
Help me if I am missing something ...
RudiC
October 24, 2017, 11:18am
2
Wildly guessing what might be "not working" I came up with
find /tmp -type f -exec sed 's/HOSTNAME=`hostname`/HOSTNAME=localhost/g' {} \;
Does this do what you want? But - this will output all modified files to stdout; correct redirections may not be that easy to find.
rdrtx1
October 24, 2017, 11:23am
3
Use -i
option for sed
(if supported). No need to escape the " =
" (or maybe for some versions of sed
).
rudic:
Wildly guessing what might be "not working" I came up with
find /tmp -type f -exec sed 's/HOSTNAME=`hostname`/HOSTNAME=localhost/g' {} \;
Does this do what you want? But - this will output all modified files to stdout; correct redirections may not be that easy to find.
My bad, still its not get substituting, I used below one
find /tmp -type f -exec sed 's/HOSTNAME=`hostname`/HOSTNAME=localhost/g' {} \;
RudiC
October 24, 2017, 1:00pm
5
Sorry: no info - no help.
I mean after executing the command the pattern is not getting changed/substituted with the new one. .. It remains the same old one...
---------- Post updated at 12:31 PM ---------- Previous update was at 12:24 PM ----------
It is working if the dirctory have only one file, but in my condition I have around 40 files in the direcyiry and in that 40 files around 7 files will have my search pattern and that has to be changed with new pattern.
RudiC
October 24, 2017, 1:31pm
7
I mean it worked perfectly on my linux system, and so there's no reason to believe it doesn't on yours unless you show us
your OS, shell, find
, and sed
versions
input data (file names, directory contents, files' contents)
DETAILED error description
system and / or error messages
What do you expect people in here to work upon?