Here's the answer:
For instance these are the texts inside the file
acpitz-virtual-0
Adapter: Virtual device
temp1: +45.0°C (crit = +90.0°C)
temp2: +45.0°C (crit = +90.0°C)
To get the +45.0°C
of temp1, use this command:
grep temp1 < theFileWithTemp.txt | awk '{print $2}'
In Bash, a glob will not expand into hidden files, so if you want to search all the files in a directory, you need to specify hidden files .*
and non-hidden *
.
To avoid the "Is a directory" errors, you could use -d skip
, but on my system I also get an error grep: .gvfs: Permission denied
†, so I suggest using -s
, which hides all error messages.
So the command you are looking for is:
grep -s "string" * .*
If you are searching files in another dir:
grep -s "string" /path/to/dir/{*,.*}
Another option is to use the dotglob
shell option, which will make a glob include hidden files.
shopt -s dotglob
grep -s "string" *
For files in another dir:
grep -s "string" /path/to/dir/*
† Someone mentioned that I shouldn't get this error. They may be right - I did some reading but couldn't make heads or tails of it myself.
Best Answer
You should really use
find
instead.Example: to search for all
.zip
files in current directory and all sub-directories try this:find . -iname \*.zip
This will list all files ending with
.zip
regarding of case. If you only want the ones with lower-case change-iname
to-name
The command
grep
searches for stings in files, not for files. You can use it withfind
to list all your.zip
files like this