Log the files found with the linux find and sed command

christopher2007

I have a folder with txt, html, jpg and png files.
Now I want to go over all textbased files (txt and html) and start a search and replace.
I did the following and it is working fine:

find ./ -iregex '.*\.\(txt\|html\)$' -exec sed -i 's/search/replace/g' {} +

But now I also want to log the files in which a replacement was executed.
Let's say I have five txt and/or html files in my folder. But in only two of them there will be something replaces because the string search is in them.
So after the command I want to have a log file (for example myLog.log) in which the two files are printed (full path).

But how can I achieve such a command?
The sed command does not have such a parameter/option.

Archemar

You will have to search fist for search pattern, then sed, and log.

try (line break for readability)

find ./ -iregex '.*\.\(txt\|html\)$' \
    -exec grep -q search {} \;  \
    -print \
    -exec sed -i 's/search/replace/g' {} + \
    > my-sed.log

where

  • search in -exec grep -q search {} \; is your search pattern. Note that you can't use + who will match more that one file.
  • -print print matched file, and thus can log

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Linux find command copy found files

From Dev

How to continuously tail a log, find all files (sed), and display (cat) the found files

From Dev

How to concatenate files found by the find command in bash

From Dev

Command: find and delete log files - deep explanation

From Dev

find log files recursively and print "INVALID" if no log found (bash)

From Dev

Sed command not found

From Dev

linux command to find files and replace with another file

From Dev

Ignore list of files in Find command Linux/ Unix

From Dev

Log Extract: SED Command

From Dev

How to make linux sed command find match ip address

From Dev

How to change permissions of multiple files found with find command?

From Dev

Sed - find and run command

From Dev

How to get absolute path of found file using 'find' command in Linux?

From Dev

Linux command line utility for watching log files live?

From Dev

How copy and rename files found in "find" function Linux?

From Dev

log4cpp: Linux can't find the lib files

From Dev

find and reverse text in multiple files with tac command in linux

From Dev

What is a Linux command to find files containing some strings but not another?

From Dev

Linux command to find and remove text from several files at once

From Dev

Pipelined Sed does not work on found filename inside Bash command substitution when invoked from Find "-exec"

From Dev

Parsing log file with sed in linux

From Dev

Sed command on Linux only matches 1, where on Solaris multiple matches are found

From Dev

Sed command on Linux only matches 1, where on Solaris multiple matches are found

From Dev

Sed command for merging multiple files

From Dev

sed command is working in solaris but not in Linux

From Dev

How to use find command with sed and awk to remove duplicate IP from files

From Dev

How to use find command with sed and awk to remove duplicate IP from files

From Dev

Find files and execute command

From Dev

SED replacement in a set of files in Linux

Related Related

  1. 1

    Linux find command copy found files

  2. 2

    How to continuously tail a log, find all files (sed), and display (cat) the found files

  3. 3

    How to concatenate files found by the find command in bash

  4. 4

    Command: find and delete log files - deep explanation

  5. 5

    find log files recursively and print "INVALID" if no log found (bash)

  6. 6

    Sed command not found

  7. 7

    linux command to find files and replace with another file

  8. 8

    Ignore list of files in Find command Linux/ Unix

  9. 9

    Log Extract: SED Command

  10. 10

    How to make linux sed command find match ip address

  11. 11

    How to change permissions of multiple files found with find command?

  12. 12

    Sed - find and run command

  13. 13

    How to get absolute path of found file using 'find' command in Linux?

  14. 14

    Linux command line utility for watching log files live?

  15. 15

    How copy and rename files found in "find" function Linux?

  16. 16

    log4cpp: Linux can't find the lib files

  17. 17

    find and reverse text in multiple files with tac command in linux

  18. 18

    What is a Linux command to find files containing some strings but not another?

  19. 19

    Linux command to find and remove text from several files at once

  20. 20

    Pipelined Sed does not work on found filename inside Bash command substitution when invoked from Find "-exec"

  21. 21

    Parsing log file with sed in linux

  22. 22

    Sed command on Linux only matches 1, where on Solaris multiple matches are found

  23. 23

    Sed command on Linux only matches 1, where on Solaris multiple matches are found

  24. 24

    Sed command for merging multiple files

  25. 25

    sed command is working in solaris but not in Linux

  26. 26

    How to use find command with sed and awk to remove duplicate IP from files

  27. 27

    How to use find command with sed and awk to remove duplicate IP from files

  28. 28

    Find files and execute command

  29. 29

    SED replacement in a set of files in Linux

HotTag

Archive