Search code examples
listunixgrepmessagemove

How to move files that contains certain message on it to another folder (Unix Korn Shell)


I'm trying to move some files that contain message "File was not FOUND" on it and I'm getting a result but I have to move all of them only with 1 line of code, at this point I have got now the files names, but can't move to another directory.

I have done this

mv $(grep "File was not FOUND" FilesToMove/Test* | cut -d ":" -f1) TargetDirectory

when I execute only this line grep "File was not FOUND" FilesToMove/Test* | cut -d ":" -f1 I'm geting the files that I want, but when I do with the mv to the target directory I got mv: FilesToMove/Test_file: No such file or directory

Do you have any suggestion? I also tried with:

grep "File was not FOUND" FilesToMove/Test* | cut -d ":" -f1 | xargs mv -t TargetDirectory

Also is not working, i'm getting this:

mv: unknown option -- t usage: mv [-bfhinuv] [-S suff] source target mv [-bfhinuv] [-S suff] source ... directory

any idea?


Solution

  • mv $(grep -l "File was not FOUND" FilesToMove/Test*) TargetDirectory