Reputation: 9569
If I run the command echo abc | sed 's/b/\'$'\n'/
at a terminal, I get the output:
a
c
But if run the following SAS code on on the same server, reading the output of exactly the same command,
filename cmd pipe "echo abc | sed 's/b/\'$'\n'/";
data _null_;
infile cmd;
input;
put _infile_;
run;
I get this in the log instead:
a$nc
How can I make the SAS pipe output match what I get in the terminal?
Further details
I'm using SAS 9.1.3 on Solaris 10 / SunOS 5.1. The Solaris version of sed I'm using does not support \n escape sequences for newlines in regexes, hence the shell substitution in the command above. If I run
echo abc | sed s/b/\n/
I get the following output (in a terminal):
anc
I do not have the option of using any other version of sed.
I already have a tr
-based solution, but I would like to find a way of making this work in sed if possible, so that I can replace longer strings with newlines.
Upvotes: 1
Views: 219
Reputation: 6333
i don't know about SAS, but the problem could be quite universal in various languages, which is: languages fork commands without a shell, therefore your pipe is not recognized. you need to change your code into bash -c "echo abc | sed 's/b/\'$'\n'/"
. you need to deal with quotes, of course.
Upvotes: 4