Skip to main content
added 147 characters in body
Source Link
thanasisp
  • 8.5k
  • 2
  • 29
  • 40

You can use something like this:

find . -type f -name '*q2*.html' -execdir sh -c '
    your/script "$1" > invalid.txt
    grep -q "Error:" invalid.txt || mv invalid.txt valid.txt
' sh {} \;

Note that you will be overwriting the (in)valid.txt file if you have more than one html files matching your find, into the same directory. You would probably like to include $(basename "$1") into the output file namefilename to make its name unique per directory.

With -execdir, the command is executed into the directory of every file found.

grep -q silently exits with failure (1) if no Error: found, so the command after || is executed. If error found, grep exits with success (0) and the mv is not executed.

You probably want to add some more for catching cases like some error of your script. Also ensure that the search pattern cannot exist for a valid file.


Another approach, independent of what messages your program is printing, is to use exit codes.

import sys to your python script and use sys.exit(0) for a valid file, or sys.exit(42) for an invalid one. After execution, you parse the exit code ($?) and decide what to do.

See also: https://tldp.org/LDP/abs/html/exitcodes.html

Example:

your/script "$1" > output.txt
result=$?
((result == 0)) && do stuff for valid file
((result == 42)) && do stuff for invalid file

You can use something like this:

find . -type f -name '*q2*.html' -execdir sh -c '
    your/script "$1" > invalid.txt
    grep -q "Error:" invalid.txt || mv invalid.txt valid.txt
' sh {} \;

Note that you will be overwriting the (in)valid.txt file if you have more than one html files matching your find, into the same directory. You would probably like to include $(basename "$1") into the output file name to make its name unique per directory.

With -execdir, the command is executed into the directory of every file found.

grep -q silently exits with failure (1) if no Error: found, so the command after || is executed. If error found, grep exits with success (0) and the mv is not executed.

You probably want to add some more for catching cases like some error of your script. Also ensure that the search pattern cannot exist for a valid file.


Another approach, independent of what messages your program is printing, is to use exit codes.

import sys to your python script and use sys.exit(0) for a valid file, or sys.exit(42) for an invalid one. After execution, you parse the exit code ($?) and decide what to do.

See also: https://tldp.org/LDP/abs/html/exitcodes.html

Example:

your/script "$1" > output.txt
result=$?
((result == 0)) && do stuff for valid file
((result == 42)) && do stuff for invalid file

You can use something like this:

find . -type f -name '*q2*.html' -execdir sh -c '
    your/script "$1" > invalid.txt
    grep -q "Error:" invalid.txt || mv invalid.txt valid.txt
' sh {} \;

Note that you will be overwriting the (in)valid.txt file if you have more than one html files matching your find, into the same directory. You would probably like to include $(basename "$1") into the output filename to make its name unique per directory.

With -execdir, the command is executed into the directory of every file found.

grep -q silently exits with failure (1) if no Error: found, so the command after || is executed. If error found, grep exits with success (0) and the mv is not executed.

You probably want to add some more for catching cases like some error of your script. Also ensure that the search pattern cannot exist for a valid file.


Another approach, independent of what messages your program is printing, is to use exit codes.

import sys to your python script and use sys.exit(0) for a valid file, or sys.exit(42) for an invalid one. After execution, you parse the exit code ($?) and decide what to do.

See also: https://tldp.org/LDP/abs/html/exitcodes.html

Example:

your/script "$1" > output.txt
result=$?
((result == 0)) && do stuff for valid file
((result == 42)) && do stuff for invalid file
added 147 characters in body
Source Link
thanasisp
  • 8.5k
  • 2
  • 29
  • 40

You can use something like this:

find . -type f -name "*q2*'*q2*.html"html' -execdir sh -c '
    your/script $1"$1" > invalid.txt
    grep -q "Error:" invalid.txt || mv invalid.txt valid.txt
' sh {} \;

Note that you will be overwriting the valid/invalid(in)valid.txt file if you have more than one html html files matching your find, into the same directory. You would probably like to include    $(basename $1"$1") into the output file name to make its name unique for theper directory.

With -execdir, the command is executed into the directory of every file found.

grep -q silently exits with failure (1) if no Error: found, so the command after || is executed. If error found, grepgrep exits with success (0) and the mv is not executed.

You probably want to add some more for catching cases like some error of your script. Also ensure that the search pattern cannot exist for a valid file.


Another approach, independent of what messages your program is printing, is to use exit codes.

import sys to your python script and use sys.exit(0) for a valid file, or sys.exit(42) for an invalid one. After execution, you parse the exit code ($?) and decide what to do.

See also: https://tldp.org/LDP/abs/html/exitcodes.html

Example:

your/script "$1" > output.txt
result=$?
((result == 0)) && do stuff for valid file
((result == 42)) && do stuff for invalid file

You can use something like this:

find . -type f -name "*q2*.html" -execdir sh -c '
    your/script $1 > invalid.txt
    grep -q "Error:" invalid.txt || mv invalid.txt valid.txt
' sh {} \;

Note that you will be overwriting the valid/invalid file if you have more than one html files matching your find, into the same directory. You would probably like to include  $(basename $1) into the output file name to make its name unique for the directory.

With -execdir, the command is executed into the directory of every file found.

grep -q silently exits with failure (1) if no Error: found, so the command after || is executed. If error found, grep exits with success (0) and the mv is not executed.

You probably want to add some more for catching cases like some error of your script. Also ensure that the search pattern cannot exist for a valid file.


Another approach, independent of what messages your program is printing, is to use exit codes.

import sys to your python script and use sys.exit(0) for a valid file, or sys.exit(42) for an invalid one. After execution, you parse the exit code ($?) and decide what to do.

See also: https://tldp.org/LDP/abs/html/exitcodes.html

You can use something like this:

find . -type f -name '*q2*.html' -execdir sh -c '
    your/script "$1" > invalid.txt
    grep -q "Error:" invalid.txt || mv invalid.txt valid.txt
' sh {} \;

Note that you will be overwriting the (in)valid.txt file if you have more than one html files matching your find, into the same directory. You would probably like to include  $(basename "$1") into the output file name to make its name unique per directory.

With -execdir, the command is executed into the directory of every file found.

grep -q silently exits with failure (1) if no Error: found, so the command after || is executed. If error found, grep exits with success (0) and the mv is not executed.

You probably want to add some more for catching cases like some error of your script. Also ensure that the search pattern cannot exist for a valid file.


Another approach, independent of what messages your program is printing, is to use exit codes.

import sys to your python script and use sys.exit(0) for a valid file, or sys.exit(42) for an invalid one. After execution, you parse the exit code ($?) and decide what to do.

See also: https://tldp.org/LDP/abs/html/exitcodes.html

Example:

your/script "$1" > output.txt
result=$?
((result == 0)) && do stuff for valid file
((result == 42)) && do stuff for invalid file
Source Link
thanasisp
  • 8.5k
  • 2
  • 29
  • 40

You can use something like this:

find . -type f -name "*q2*.html" -execdir sh -c '
    your/script $1 > invalid.txt
    grep -q "Error:" invalid.txt || mv invalid.txt valid.txt
' sh {} \;

Note that you will be overwriting the valid/invalid file if you have more than one html files matching your find, into the same directory. You would probably like to include $(basename $1) into the output file name to make its name unique for the directory.

With -execdir, the command is executed into the directory of every file found.

grep -q silently exits with failure (1) if no Error: found, so the command after || is executed. If error found, grep exits with success (0) and the mv is not executed.

You probably want to add some more for catching cases like some error of your script. Also ensure that the search pattern cannot exist for a valid file.


Another approach, independent of what messages your program is printing, is to use exit codes.

import sys to your python script and use sys.exit(0) for a valid file, or sys.exit(42) for an invalid one. After execution, you parse the exit code ($?) and decide what to do.

See also: https://tldp.org/LDP/abs/html/exitcodes.html