Name
w
Synopsis
[address1
[,address2
]]wfile
Append contents of pattern space to
file. This action occurs when the command is
encountered rather than when the pattern space is output. Exactly
one space must separate the w
and the filename. This command creates the file if it does not
exist; if the file exists, its contents are overwritten each time
the script is executed. Multiple write commands that direct output
to the same file append to the end of the file.
Most Unix versions of sed allow a maximum of only 10 different files to be opened in a script. The GNU version does not have this limit.
GNU sed allows you to use
the special filenames /dev/stdout
and /dev/stderr
to write to standard output
or standard error, respectively.
Example
# Store HTML tables in a file /<table/,/<\/table>/w tables.html
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.