Is it possible?
I am a Linux user.I know little about grep commands.I want to search a string in one folder all files except one file.I used this command (grep -ir "string" folder path) but it checks all files in that folder.Can anyone tell the solution?
Thanks |
Quote:
Make a list (file) inside the folder where you run your grep(pings); example Code:
~$ touch ./myexclude Code:
~$ grep -lir 'pattern' * --exclude-from=./myexclude If you want to exclude a directory you can do the same with '--exclude-dir=DIRECTORY'. Hope that helps. Good luck. m.m. |
If it is only one file that you want to exclude (or one specific pattern) you don't need to create a file, you can use the --exclude= option directly.
As always, more infos with Code:
man grep |
You can take help from man pages using cmd "man grep".
Anyway, let you have following files: ls -la <directory> ... A.txt ... B.txt ... C.txt ... D.txt ... E.txt Then invoke following cmd to igonre C.txt file: ls -la <directory> | grep -v "C.txt" Use -v option with grep to ignore the string. |
Two more (bash-specific) options for you. They both involving globbing, and can be used with all commands.
1) Use extended globbing. Code:
shopt -s extglob Code:
GLOBIGNORE=.*:unwantedfile.txt:*.sh |
All times are GMT -5. The time now is 02:02 PM. |