Save modifications in place with awk

前端 未结 8 1964
轻奢々
轻奢々 2020-11-21 23:32

I am learning awk and I would like to know if there is an option to write changes to file, similar to sed where I would use -i option

相关标签:
8条回答
  • 2020-11-22 00:06

    following won't work

    echo $(awk '{awk code}' file) > file
    

    this should work

    echo "$(awk '{awk code}' file)" > file
    
    0 讨论(0)
  • 2020-11-22 00:08

    An alternative is to use sponge:

    awk '{print $0}' your_file | sponge your_file
    

    Where you replace '{print $0}' by your awk script and your_file by the name of the file you want to edit in place.

    sponge absorbs entirely the input before saving it to the file.

    0 讨论(0)
提交回复
热议问题