Leave the cat
s out of this; they're happier curled up in a corner and left in peace. The first sed
in each pipeline can read the file.
You should be able to combine those separate sed
commands into one per pipeline, too. That is, your current command:
cat /crawler/bc_daemon.php |
sed "s/PORT2/${PORT}/ig" |
sed 's/IP2/IPADDRESS/ig' |
sed 's/USER2/USER/ig' |
sed 's/PASS2/PASSWORD/ig' > bc_daemon.php
should be:
sed -e "s/PORT2/${PORT}/ig" \
-e 's/IP2/IPADDRESS/ig' \
-e 's/USER2/USER/ig' \
-e 's/PASS2/PASSWORD/ig' \
/crawler/bc_daemon.php > bc_daemon.php
This ignores the issue with the unknown option to the s///
command, which is probably might be referring to the i
flag. The GNU sed
man page on Linux doesn't list that, but the online GNU sed
manual does list both i
and I
as options for case-insensitivity, so that should not be the problem. One other possibility is that the expansion of ${PORT}
contains a slash; that could cause the error you're seeing (or, that the problem is in the second pipeline instead of the first).
If you are not using GNU sed
(and the error suggests that you might not be), you might need to brute-force the patterns.
sed -e "s/[pP][oO][rR][tT]2/${PORT}/g" \
-e 's/[iI][pP]2/IPADDRESS/g' \
-e 's/[uU][sS][eE][rR]2/USER/g' \
-e 's/[pP][aA][sS][sS]2/PASSWORD/g' \
/crawler/bc_daemon.php > bc_daemon.php
Note that both these pipelines will fail horribly if the current directory is /crawler
because the output redirection will clobber the input file before the command is executed.