I have a file in Linux, I would like to display lines which contain a specific string in that file, how to do this?
I have a file in Linux, I would like to display lines which contain a specific string in that file, how to do this?
Besides grep, you can also use other utilities such as awk or sed
Here is a few examples. Let say you want to search for a string is in the file named GPL.
Your sample file
$ cat -n GPL
1 The GNU General Public License is a free, copyleft license for
2 The licenses for most software and other practical works are designed
3 the GNU General Public License is intended to guarantee your freedom to
4 GNU General Public License for most of our software;
1. grep
$ grep is GPL
The GNU General Public License is a free, copyleft license for
the GNU General Public License is intended to guarantee your freedom to
2. awk
$ awk /is/ GPL
The GNU General Public License is a free, copyleft license for
the GNU General Public License is intended to guarantee your freedom to
3. sed
$ sed -n '/is/p' GPL
The GNU General Public License is a free, copyleft license for
the GNU General Public License is intended to guarantee your freedom to
Write the queue job information in long format to text file
qstat -f > queue.txt
Grep job names
grep 'Job_Name' queue.txt