Linux Text Processors

During pentests, you will often find yourself using a Linux machine without access to the Graphical User Interface (GUI). As you can imagine, this can make editing/looking through text-based files a PITA if you're looking through large files.

To help with this, here are a few popular text-processing tools made for the command line that can help you manipulate text-based files:

Grep

Grep allows you to search for a string using either plaintext or regular expressions (regex).

grep <options> [pattern] [file]

OPTIONS
-i                   Ignore Case Distinctions
-v                   Invert Match
-a                   Assume Binary Files Are Text
-G                   Pattern Is A Regular Expression

Here is an example where I'm searching for the string 'hyperbeam' in the file weelee.txt.

grep -i hyperbeam weelee.txt

Cut

Cut is handy for parsing and manipulating structured text data, such as delimited files (e.g., CSV files) or fixed-width text files.

cut <options> [file]

OPTIONS
-b number            Prints The Specified Number Of Characters From Each Line
-c number            Prints The Specified Characters By Index From Each Line
-d                   Delimiter
-f                   Select Only These Fields

Here is an example where I'm writing just the first column of pokedex.csv to a new file:

Sed

Sed is excellent for substituting text in a file but can be used for various other things. The syntax for Sed is based on regular expressions, which allows for complex text manipulation.

Here are a few examples of Sed commands you may want to use:

Awk

Awk is another text manipulation tool that can filter specific lines and strings in a text file.

Here are a few examples of Awk commands you may want to use:

Tr

Tr is often used to perform character-level manipulation of characters in a file.

Here are a few examples of Tr commands you may want to use:

Last updated