using sed to insert file content into a file BEFORE a pattern

St3an

I'm new to sed, I'm trying to insert the content of a BFile into the file AFile, BEFORE a pattern (in AFile)

Hereafter's what I've tried :

sed -i '/blah Blah/r BFile' AFile : it's inserting the content of BFile AFTER the pattern in AFile.

sed -i '/blah Blah/i BFile' AFile : it's inserting the string 'BFile' BEFORE the pattern in AFile.

... hmmm

I'm conscious it's because of a wrong comprehension of regexp or sed : I can't understand how the /i and /r work here... I can't find any help in sed --help

Anyone understanding my point ?

Regards,

Stan

potong

This might work for you (GNU sed):

sed $'/blah Blah/{e cat Bfile\n}' AFile

or:

sed -e 'N;/\n.*blah Blah/{r Bfile' -e '};P;D' AFile

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

insert carriage return before a regular expression in a text file using unix shell

来自分类Dev

Sed: How to replace a string found after a specific pattern is located in a file

来自分类Dev

Apply pattern on file stream

来自分类Dev

How can I use sed to make thousands of substitutions in a file using a reference file?

来自分类Dev

How to write a big ISO file into a few disks for using its content?

来自分类Dev

Search for Phone Number Pattern in a file

来自分类Dev

Insert File stream to std::map

来自分类Dev

Strip off word pattern at the end of string using sed

来自分类Dev

Strip off word pattern at the end of string using sed

来自分类Dev

Select and remove lines matching a pattern from a file

来自分类Dev

Insert text into file after a specific text

来自分类Dev

File transfer using thread

来自分类Dev

java api to get a file content for enterprise github

来自分类Dev

Missing line content when reading file with bash

来自分类Dev

Content of file in Visual Studio sometimes became gray

来自分类Dev

Replace QML file content by another one

来自分类Dev

ip日志file_get_content()

来自分类Dev

与file_get_content相反的方法

来自分类Dev

用file_get_content替换curl

来自分类Dev

在 file_get_content() 函数中出错

来自分类Dev

sed:-i和> file有什么区别?

来自分类Dev

How do I get Ruby to search for a pattern on the tail of a local file?

来自分类Dev

ngf-pattern无法用于ng-file-upload

来自分类Dev

linux command to shuffle a large csv file to alternate rows according to a pattern

来自分类Dev

ksh / bash通过cat file | sed命令通过sed格式化文件

来自分类Dev

How to append the lines using SED or AWK until a particular pattern does not matches?

来自分类Dev

Using a Resource File on buttons OnClientClick

来自分类Dev

Vim quickfix, using an existing file?

来自分类Dev

Duplicate File Using Applescript/Terminal

Related 相关文章

  1. 1

    insert carriage return before a regular expression in a text file using unix shell

  2. 2

    Sed: How to replace a string found after a specific pattern is located in a file

  3. 3

    Apply pattern on file stream

  4. 4

    How can I use sed to make thousands of substitutions in a file using a reference file?

  5. 5

    How to write a big ISO file into a few disks for using its content?

  6. 6

    Search for Phone Number Pattern in a file

  7. 7

    Insert File stream to std::map

  8. 8

    Strip off word pattern at the end of string using sed

  9. 9

    Strip off word pattern at the end of string using sed

  10. 10

    Select and remove lines matching a pattern from a file

  11. 11

    Insert text into file after a specific text

  12. 12

    File transfer using thread

  13. 13

    java api to get a file content for enterprise github

  14. 14

    Missing line content when reading file with bash

  15. 15

    Content of file in Visual Studio sometimes became gray

  16. 16

    Replace QML file content by another one

  17. 17

    ip日志file_get_content()

  18. 18

    与file_get_content相反的方法

  19. 19

    用file_get_content替换curl

  20. 20

    在 file_get_content() 函数中出错

  21. 21

    sed:-i和> file有什么区别?

  22. 22

    How do I get Ruby to search for a pattern on the tail of a local file?

  23. 23

    ngf-pattern无法用于ng-file-upload

  24. 24

    linux command to shuffle a large csv file to alternate rows according to a pattern

  25. 25

    ksh / bash通过cat file | sed命令通过sed格式化文件

  26. 26

    How to append the lines using SED or AWK until a particular pattern does not matches?

  27. 27

    Using a Resource File on buttons OnClientClick

  28. 28

    Vim quickfix, using an existing file?

  29. 29

    Duplicate File Using Applescript/Terminal

热门标签

归档