I need to break ‘aaa bbb’ into
aaa
bbb
In one single line of code.
In gnused, I can:
print 'aaa bbb' | sed 's/ /\n/g'
In bash, I can:
echo 'aaa bbb' | sed 's/ '"/`echo \\\n`/"
But in ksh/zsh, with at&t sed in AIX, none of this works:
print 'aaa bbb' | sed "s/ /`echo -e \\\n`/"
print 'aaa bbb' | sed 's/ '"/`echo \\\n`/"
print 'aaa bbb' | sed "s/ /`echo \\\n`/"
Is there any workaround in sed, with in one line?
Assuming exactly one space in the line:
To do this for every space: (I think I am triggering a bug in my local
sedhere; I couldn’t combine the commands as above)(You can see why GNU sed was extended to handle this case better.) You can do all sorts of things with the hold space, and even more if you use conditional branching (
s/.../.../;thereifmatched).