New answers tagged

3 votes
Accepted

bash: string variable contains asterisk. how to use this variable for searching etc with grep, sed?

For grep, you can use -F to use fixed strings instead of regexes. For sed, it's much more complex. I'd probably switch to Perl which can help you with its \Q/quotemeta function. #!/bin/bash s="...
choroba's user avatar
  • 45.9k
1 vote
Accepted

Bash script variable syntax: with some commands it works, with others it does not

Don't put quotes around tilde ~ if you expect the shell to expand it to your home, so: SSH_CONFIG_FILE=~/.ssh/config if you have space(s); do var=~/'foo bar/file' With the quotes on tilde, you ...
Gilles Quénot's user avatar
2 votes

sed: update 2 similar variables in a file but keep the upper and lowercase

As a rule, you should not embed data in the code arguments of language interpreters whether they're shells, sed, awk, perl, python, etc. Doing so invariably introduces command injection ...
Stéphane Chazelas's user avatar
0 votes
Accepted

sed: update 2 similar variables in a file but keep the upper and lowercase

Use grouping \(...\) and referencing (\1 for the first group, \2 for the second etc.): sed -i "s/\(sid=\).*/\1${CName^^}/gI" dbca2.rsp For turning the user input to uppercase, the shell is ...
Philippos's user avatar
  • 13.3k
0 votes

Use SED to replace part of a current variable with user input variable

To set the new name dynamically, by a variable, for instance (here only shown for the permanent change): Close to your attempt: sed -i "s/gdbName=*.MY.DOMAIN.COM/gdbName=$CDBName/" somefile....
user unknown's user avatar
  • 10.3k
0 votes
Accepted

Use SED to replace part of a current variable with user input variable

Assuming you want to modify a file wherein you have some line, gdbName=Test.MY.DOMAIN.COM Then this could be done using sed "s/^\(gdbName\)=Test\./\1=$CDBName./" somefile or, if you need ...
Kusalananda's user avatar
  • 323k

Top 50 recent answers are included