Search code examples
sed

How to back reference the filename in sed?


I tried to read the filename for the w command from the input data.

echo 'abc123' | sed -n 's/^abc//w &'

But it does not work. Instead of writing "123" into the file "abc" it creates the file "&".

Is it possible anyhow?


Solution

  • I tried to read the filename for the w command from the input data.
    Is it possible anyhow?

    No, the filename argument to w is not part of the regex substitution.