Searching and Processing Text

Searching Text

grep

  • grep - print lines that match patterns

grep file file-list.txt 
    file1.txt
    file2.txt
    file3.txt
# Output higlights the matching text (colors enabled in the shell)

# To search for lines that DO NOT match text
grep -v 1 file-list.txt
    file2.txt
    file3.txt

grep -v root /etc/passwd | less

# Check the grep man page
man grep

sort

  • sort - display sorted lines of text files

uniq

  • uniq - report or omit repeated lines, filtering adjacent matching lines from the input

wc

  • wc - print number of lines, words and bytes in a file

  • Use pipes to create a command that uses all 4 tools:

Manipulating Text

sed

  • sed - stream editor for filtering and transforming text

    • A stream editor is used to perform basic text transformations on an input stream.

    • sed manipulates text line by line

awk

  • awk - pattern scanning and text processing language

    • awk breaks each line of input into separate fields or columns using specific delimiters.

    • The default delimiter is "space".

    • Each field is numbered starting at 1.

tr

  • tr - translate, squeeze, delete characters from the standard input

  • One of the most powerfull aspects of these tools is the ability to use regular expressions.


Last updated

Was this helpful?