how to find a text in a file?
in directory so many files are there. if we want to find some text in all the files, what is command is to be used.
|
`grep` would be my first choice.
|
yes grep will do:
here are some examples: Code:
grep "My text" * Code:
grep --color "My text" * Code:
grep -R --color -B4 -A2 "My text" * man grep for more help Angel |
you can try this way also:
Code:
find .-name *.* | xargs grep "string" |
Quote:
Code:
find . Code:
find .-name *.* The next problem you will face is that the "*.*" will be expanded by the shell, not the find command. As an example, assume the current directory contains three files as shown below: Code:
ls -1 Code:
find . -name I could go on with all the problems with this find construction, but in deference to the OP I'll cut to the chase. If you want to search for text in a single file use this. Code:
grep 'text to search for' filename Code:
grep -i 'text to search for' filename Code:
# search all ".txt" files in the current dir Code:
grep -i 'text to search for' *.TXT Code:
grep -i -R 'text to search for' *.txt Code:
man grep http://www.regular-expressions.info/ http://google.com/search?q=regular%20expressions |
Quote:
In Linux, there is no such thing as file extensions. Just use * instead. |
grep -i 'dsfas' * works fine for me.
thanq all |
All times are GMT -5. The time now is 12:35 PM. |