How to show only whole words with grep on Linux when searching a file.

Some very useful grep tips for a UNIX or Linux user This is a very useful example, this is how to stop grep finding letters before the start of the search term “file*[s-t]”. The \b operator is an end of word marker. ┌──[[email protected]]─[~] └──╼ ╼ $ grep -n "\bfile*[s-t]\b" /usr/share/dict/words 46437:files 46438:filet 46439:filet’s┌──[[email protected]]─[~] └──╼ ╼ … Read more

Use grep to search through source code trees fast and find what you are looking for.

Using the grep utility to search through source code can take a long time when you are searching for certain text. But this can be made easier if you use grep. The command below: grep -rn –include "*.*" "winlogon" .grep -rn –include "*.*" "winlogon" . Will search recursively through a source code tree and find … Read more

Searching for words in random data. This is very interesting.

I have found a nice method of searching randomly generated data for certain words. This takes a while but can bear fruit in the end. Here is an example, this is searching through the /dev/urandom file and then finding an instance of the word “linux”. jason@jason-Lenovo-H50-55:~$ time tr -cd [:lower:] < /dev/urandom | fold -w … Read more

How to find matching files when using grep to search for files containing text.

The grep utility is very useful when searching for text in files. This can be used recursively to find matching files. This tip will return the full path to all files containing the text you are looking for. 4.4 Thu Apr 23 jason@Yog-Sothoth 1: $ grep -r -H "noclip"4.4 Thu Apr 23 jason@Yog-Sothoth 1: $ … Read more

How to search a file with grep for certain hexadecimal values.

The grep utility is very useful for searching for files and text snippets. It can also be used to search a file for certain values in hexadecimal. In the example below, I am searching for the text “JFIF” in hexadecimal in certain files. This will tell me that they are jpg image files. The hexadecimal … Read more

How to search through textfiles in a folder when you are stuck on Windows.

Windows has quite a few useful utilities for searching text. The findstr utility allows searching through a folder full of text files for a certain string. Here is an example. >findstr /S /R "money_quest_update" *.*>findstr /S /R "money_quest_update" *.* And this is how to search for text strings in a folder. E:\shadowofchernobyl\gamedata>findstr /S /R "money_quest_update" … Read more

Some awesome tricks with awk, grep and sed.

Reading a large text file and then finding all words that contain between 5 and 7 vowels. Notice I am not using cat. jason@Yog-Sothoth:~/Documents$ egrep ‘^([^aieou]*[aieou]){5,7}[^aieou]*$’ < pg768.txt | wc -l 284jason@Yog-Sothoth:~/Documents$ egrep ‘^([^aieou]*[aieou]){5,7}[^aieou]*$’ < pg768.txt | wc -l 284 Count the number of times a single word appears in a text file. jason@Yog-Sothoth:~/Documents$ egrep … Read more

Useful Linux/UNIX commands.

Using wild-cards to display various files in a folder with ls. I recently needed to check whether certain files were in the /usr/lib folder and I used the ls command to do this. to find all files related to the Perl programming language in the /usr/lib directory. ubuntu ~ $ ls /usr/lib/*perl* /usr/lib/libperl.so.5.18 /usr/lib/libperl.so.5.18.2   … Read more

The proper way to use grep without cat. And some nice tricks.

This is the proper way to use grep. You do not need to use cat at all. This method works well and is one command, not two piping together. jason@jason-desktop:~/Documents$ grep apt-get ../.bash_history sudo apt-get update sudo apt-get install me-tv sudo apt-get update && sudo apt-get install xvst apt-get moo apt-get moojason@jason-desktop:~/Documents$ grep apt-get ../.bash_history … Read more

How to get information out of the system logfiles on Linux. Showing failed logins.

There are a few ways to get information out of the /var/log files using the Linux command line. Here are a few examples. Show the history of apt commands on your Linux box with this command. jason@eyjafjallajkull:~$ grep ‘Commandline: ‘ /var/log/apt/history.log Commandline: apt-get upgrade Commandline: apt-get install gnome-alsamixer Commandline: apt-get install indicator-sound-switcher Commandline: apt-get upgrade … Read more

A better way to use grep to search files and folders. You do not need to use cat.

This is how to use grep to search a file without using cat. homer@neo:~/Documents$ grep "gcc" ../.bash_history gcc my.cpp gcc gcc hello.java gcc hello.java gcc hello.java gcc hello.java gcc mein.c -o mein gcc -c99 mein.c -o mein gcc -std=c99 mein.c -o mein gcc hello.c -o hello gcc hello.c -o hello gcc hello.c -o hello gcc … Read more

How to filter text with the sed command. This is useful for various shell tricks.

Using wildcards on the Linux command line This is a standard listing of files with wildcards in the bash shell. homer@deep-thought ~/Documents $ ls *.wad basenew.wad cc4-tex.wad city-heat.wad dark.wad doom.wad plutonia.wad scythe2.wad SKYTEST.wad brick.wad cchest4.wad consoleCopy.wad doom2.wad hexen.wad RIII.wad scythex.wad SODfinal.wadhomer@deep-thought ~/Documents $ ls *.wad basenew.wad cc4-tex.wad city-heat.wad dark.wad doom.wad plutonia.wad scythe2.wad SKYTEST.wad brick.wad cchest4.wad … Read more