Skip to main content
added 172 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

With the GNU implementation of sed:

$ sed -e '/^sp^sp|/{R file2' -e 'd}' file1
sp|B7UM99|TIR_ECO27OS=Escherichia coli
MPIGNLGNNVNGNHLIPPAPP.....
sp|P0ACF8|HNS_ECOLI=Human
MSEALKILNNIRTLRAQ........
sp|P24232|HMP_ECOLI=Flavohemoprotein
MLDAQTIATVKATIPLLVET..........

Where the R file command (a GNU non-standard extension) pulls one line from the file (not into the pattern space) and prints it, while d (standard) discards the pattern space.

Add the -i option to edit file1 in-place.

With the GNU implementation of sed:

$ sed -e '/^sp/{R file2' -e 'd}' file1
sp|B7UM99|TIR_ECO27OS=Escherichia coli
MPIGNLGNNVNGNHLIPPAPP.....
sp|P0ACF8|HNS_ECOLI=Human
MSEALKILNNIRTLRAQ........
sp|P24232|HMP_ECOLI=Flavohemoprotein
MLDAQTIATVKATIPLLVET..........

Add the -i option to edit file1 in-place.

With the GNU implementation of sed:

$ sed -e '/^sp|/{R file2' -e 'd}' file1
sp|B7UM99|TIR_ECO27OS=Escherichia coli
MPIGNLGNNVNGNHLIPPAPP.....
sp|P0ACF8|HNS_ECOLI=Human
MSEALKILNNIRTLRAQ........
sp|P24232|HMP_ECOLI=Flavohemoprotein
MLDAQTIATVKATIPLLVET..........

Where the R file command (a GNU non-standard extension) pulls one line from the file (not into the pattern space) and prints it, while d (standard) discards the pattern space.

Add the -i option to edit file1 in-place.

Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

With the GNU implementation of sed:

$ sed -e '/^sp/{R file2' -e 'd}' file1
sp|B7UM99|TIR_ECO27OS=Escherichia coli
MPIGNLGNNVNGNHLIPPAPP.....
sp|P0ACF8|HNS_ECOLI=Human
MSEALKILNNIRTLRAQ........
sp|P24232|HMP_ECOLI=Flavohemoprotein
MLDAQTIATVKATIPLLVET..........

Add the -i option to edit file1 in-place.