Linux

Explain what each of the following commands does and give an example on how to use it:

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

  • sed: a stream editor. Can be used for various purposes like replacing a word in a file: sed -i s/salad/burger/g
    • grep: a search tool. Used to search, count or match a text in a file:
      • searching for any line that contains a word in a file: grep 'word' file.md
      • or displaying the total number of times a string appears in a file: grep -c 'This is a string' file.md
    • cut: a tool for cutting out selected portions of each line of a file:
      • syntax: cut OPTION [FILE]
        • cutting first two bytes from a word in a file: cut -b 1-2 file.md, output: wo
    • awk: a programming language that is mainly used for text processing and data extraction. It can be used to manipulate and modify text in a file:
      • syntax: awk [OPTIONS] [FILTER] [FILE] extracting a specific field from a CSV file: awk -F ',' '{print $1}' file.csv, output: first field of each line in the file