Bash: replacing a substring in pipe stdin

后端 未结 2 1019
醉话见心
醉话见心 2021-02-07 12:54

I try to replace a certain substring from the stdin with a new substring. I have to get the stdin from the pipe, after reading several files by cat. Then I want to

相关标签:
2条回答
  • 2021-02-07 13:38

    You can use the command sed.

    cat file1 file2 | sed -e 's/@path_to_file/path/to/file/' ...
    
    0 讨论(0)
  • 2021-02-07 13:46

    With Parameter Expansion:

    cat file1 file2 | while read -r line; do echo "${line/@path_to_file/path\/to\/file}"; done
    
    0 讨论(0)
提交回复
热议问题