Hi,
I need to exlucde the files which are present in exclude.txt from a directory
exlcude.txt
AUZ.txt
AUZ.chk
NZ.txt
NZ.chk
tried with below code but not working
ls -ltr | grep -v `cat exclude.lst`
Hi,
I need to exlucde the files which are present in exclude.txt from a directory
exlcude.txt
AUZ.txt
AUZ.chk
NZ.txt
NZ.chk
tried with below code but not working
ls -ltr | grep -v `cat exclude.lst`
Try
ls -ltr | grep -vFf exclude.txt
Yeah the above on worked, will it be possible to exclude the files if i am having a file like below
exclude.txt
AUZ.txt AUZ.chk
NZ.txt NZ.chk
If you are using bash or ksh93 you could try:
ls -ltr | grep -vFf <(xargs -n1 < exclude.txt)
yeah but would this same work if the file contains data with delimited separated
AUZ.txt,AUZ.chk,xyz
NZ.txt,NZ.chk,xxzz
This should exclude only
AUZ.txt
AUZ.chk
NZ.txt
NZ.chk
No, that would not, since the format of the file is one of the factors that determine the solution. If it keeps changing then the solution would need to change also. Please be clear about the format of the file and explain which part should be used, for example..
The file format can be like below
AUZ.txt,AUZ.chk,xyz
NZ.txt,NZ.chk,xxzz
And should the 3rd field be used, and if not, why not?
The third field will not be used only first two fields should only be used and those files need to be excluded while listing in directory
OK, try:
ls -ltr | grep -vFf <(cut -d, -f-2 exclude.txt | tr ',' '\n')
But please next time specify the correct format straight away in post #1