Skip to main content
Post Undeleted by Jeff Schaller
updated to account for > symbols anywhere, not just 9 different lines
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

You could use zsh with its expression-as-a-glob-qualifier to select files that only have nine such symbols:

$ hasnine() { [[ $(greptr -cdc '>' < "$REPLY" | wc -c) -eq 9 ]]; } $ mv *.fna(+hasnine) location/ 

The first line defines a function whose purpose is to create a true/false filter for files that have exactly nine lines with > symbols in them. The greptr command acts on its input, expected in the REPLY variable, deleting anything that is not a >, then asks wc to count the number of resulting characters, and then compares thethat output to 9.

The second line executes the mv command for matching *.fna files to the (example) location directory. Matching *.fna files also have to pass the expression qualifier, which is the given as the name of the function we defined.

You could use zsh with its expression-as-a-glob-qualifier to select files that only have nine such symbols:

$ hasnine() { [[ $(grep -c '>' < "$REPLY") -eq 9 ]]; } $ mv *.fna(+hasnine) location/ 

The first line defines a function whose purpose is to create a true/false filter for files that have exactly nine lines with > in them. The grep command acts on its input, expected in the REPLY variable and compares the output to 9.

The second line executes the mv command for matching *.fna files to the (example) location directory. Matching *.fna files also have to pass the expression qualifier, which is the given as the name of the function we defined.

You could use zsh with its expression-as-a-glob-qualifier to select files that only have nine such symbols:

$ hasnine() { [[ $(tr -dc '>' < "$REPLY" | wc -c) -eq 9 ]]; } $ mv *.fna(+hasnine) location/ 

The first line defines a function whose purpose is to create a true/false filter for files that have nine > symbols in them. The tr command acts on its input, expected in the REPLY variable, deleting anything that is not a >, then asks wc to count the number of resulting characters, and then compares that output to 9.

The second line executes the mv command for matching *.fna files to the (example) location directory. Matching *.fna files also have to pass the expression qualifier, which is given as the name of the function we defined.

Post Deleted by Jeff Schaller
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

You could use zsh with its expression-as-a-glob-qualifier to select files that only have nine such symbols:

$ hasnine() { [[ $(grep -c '>' < "$REPLY") -eq 9 ]]; } $ mv *.fna(+hasnine) location/ 

The first line defines a function whose purpose is to create a true/false filter for files that have exactly nine lines with > in them. The grep command acts on its input, expected in the REPLY variable and compares the output to 9.

The second line executes the mv command for matching *.fna files to the (example) location directory. Matching *.fna files also have to pass the expression qualifier, which is the given as the name of the function we defined.