I have 100 files in a specific directory that contains several records with fields delimited with commas.
I need to use a Linux command that check the lines in each file and if the line contains more than 100 comma move it to another directory.
Is it possible ?
Updated Answer
Although my original answer below is functional, Glenn's (@glennjackman) suggestion in the comments is far more concise, idiomatic, eloquent and preferable - as follows:
It basically relies on
awk
's exit status generally being0
, and then only setting it to1
when encountering files that need moving.Original Answer
This will tell you if a file has more than 100 commas on any line:
It will print
1
and exit without parsing the remainder of the file if the file has any line with more than 100, and print0
at the end if it doesn't.If you want to move them as well, use
Try this and see if it selects the correct files, and, if you like it, remove the word
echo
and run it again so it actually moves them. Back up first!