Quiero insertar el contenido del archivo 1 en el archivo 2 después de un PATRÓN coincidente. Quiero hacerlo solo después de la primera aparición del PATRÓN.
Me gustaría saber la modificación que debo hacer al siguiente comando para mis necesidades.
sed -i "/PATTERN/r file1" file2
Respuesta aceptada:
sed '/PATTERN/{
r file1
:a
n
ba
}' file2
:a
, n
, ba
es solo un ciclo que imprime todo el contenido del archivo después del PATRÓN hasta el final. y tenga en cuenta que esas 6 líneas son solo un comando, pero se necesita una nueva línea para delimitar el siguiente comando sed después de r
, :
y b
.
información adicional de info sed
:
`n'
If auto-print is not disabled, print the pattern space, then,
regardless, replace the pattern space with the next line of input.
If there is no more input then `sed' exits without processing any
more commands.
`: LABEL'
[No addresses allowed.]
Specify the location of LABEL for branch commands. In all other
respects, a no-op.
`b LABEL'
Unconditionally branch to LABEL. The LABEL may be omitted, in
which case the next cycle is started.