How to get extra context around search results from grep.

Using grep to find text strings is very useful. This may also be used to view extra text around the matches to get extra context. Use grep like this. grep -R -A 10 -B 10 ‘command arguments’ * 2>/dev/nullgrep -R -A 10 -B 10 ‘command arguments’ * 2>/dev/null This returns…

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:]…

Read More

How to recursively search with grep on Linux.

The grep utility is very useful for searching for text in files on a Linux system. It is possible to search for text or files recursively. This is very easy to do. This example is how to search for a text string recursively with grep. I have double quotes in…

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…

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 ~ $…

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…

Read More

Useful grep tricks and tips for the Linux user.

The grep command on Linux is very good for filtering text to find certain strings. This is mostly used for filtering the output of a command to narrow down what the user is looking for. Find all instances of a word in a text file. jason@DESKTOP-R72SPS3:/usr/share/X11$ grep "dark" rgb.txt 47…

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…

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…

Read More