hello
I have a file where an entry needs to be modified. an example of this entry is:
install_location=/xena/sybase/ase12_5
I need to replace xena with another hostname (`hostname` output) for example:
install_location=/dx1/sybase/ase12_5
how to do that?
thanks
eval sed 's/xena/`hostname`/' file
should work
no need for eval
sed "s/xena/`hostname`/" file
true - bad habit of mine overusing eval
thanks. but the string may change:
install_location=/xena/sybase/ase12_5
I want everything between =/ and /sybase to be replaced with the hostname
thx
bit clunky but:
sed "s_=/.*/sybase_=/`hostname`/sybase_" file
should work
vino
7
sed -e "s/\(install_location=.\)[^/]*\(\/.*\)/\1`hostname`\2/g" file
wow.
thanks.
one more thing please:
server_name=XENA
hostname=xena
need to change also these 2 lines:
everything after = to `hostname` in capital lettter for server_name and `hostname` for hostname.
could you please help?
thanks
vino
9
Perhaps something like this
sed -e "s/=\(\/\)[^/]*\(\/\)/=\1`hostname`\2/g" -e "s/=[^/][^/]*/=`hostname`/g" input.txt
I think you are better off with putting install_location, server_name and hostname in the regex part of the sed.
this will change all entries to have `hostname` after the equal (=) sign
vino
11
Yes it does. That is why I suggested you put in those strings in the regex part of sed so that you can achieve your desired output.
sed -e "s/install_location=....../g" -e "s/hostname=....../g" -e "s/server_name=....../y" input.txt
Try awk. I think awk may have a toUpper functionality.
hello,
So far all is working for replacing all needs strings.
sed -e "s/install_location=....../g" -e "s/hostname=....../g" -e "s/server_name=....../y" input.txt
but frankly I have no idea how to integrate toUpper and awk in the above sed.
any hints please?