sed command in dry run

后端 未结 3 1388
情深已故
情深已故 2021-02-02 05:51

How it is possible to make a dry run with sed?

I have this command:

find ./ -type f | xargs sed -i \'s/string1/string2/g\'

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 06:37

    Remove the -i and pipe it to less to paginate though the results. Alternatively, you can redirect the whole thing to one large file by removing the -i and appending > dryrun.out

    I should note that this script of yours will fail miserably with files that contain spaces in their name or other nefarious characters like newlines or whatnot. A better way to do it would be:

    while IFS= read -r -d $'\0' file; do
      sed -i 's/string1/string2/g' "$file"
    done < <(find ./ -type f -print0)
    

提交回复
热议问题