Browse Docs

Shell

In this section

  • ๐Ÿฆ Awk

    The Basics

    awk is treat each line as a table, by default space are separators of columns.

    General syntax is awk 'search {action}' file_to_parse.

    1# Give the value higher than 75000 in column $4
    2df | awk '$4 > 75000'   
    3
    4# Print the all line when column $4 is higher than 75000
    5df | awk '$4 > 75000 {print $0}' 
    

    But if you look for a string, the search need to be included in /search/ or ;search;.
    When you print $0 represent the all line, $1 first column, $2 second column etc.

  • ๐Ÿด Sed

    The Basics

     1sed -e 'โ€ฆ' -e 'โ€ฆ'  # Several execution 
     2sed -i             # Replace in place 
     3sed -r             # Play with REGEX
     4
     5# The most usefull
     6sed -e '/^[ ]*#/d' -e '/^$/d' <fich.>    #   openfile without empty or commented lines
     7sed 's/ -/\n -/g'                        #   replace all "-" with new lines
     8sed 's/my_match.*/ /g'                   #   remove from the match till end of line
     9sed -i '4048d;3375d' ~/.ssh/known_hosts  #   delete lines Number
    10
    11# Buffer 
    12s/.*@(.*)/$1/;                                        #  keep what is after @ put it in buffer ( ) and reuse it with $1.
    13sed -e '/^;/! s/.*-reserv.*/; Reserved: &/' file.txt  #  resuse search with &
    14
    15# Search a line
    16sed -e '/192.168.130/ s/^/#/g' -i /etc/hosts          # Comment a line 
    17sed -re 's/^;(r|R)eserved:/; Reserved:/g' file.txt    # Search several string
    18
    19# Insert - add two lines below a match pattern
    20sed -i '/.*\"description\".*/s/$/ \n  \"after\" : \"network.target\"\,\n  \"requires\" : \"network.target\"\,/g'  my_File  
    21
    22# Append
    23sed '/WORD/ a Add this line after every line with WORD'
    24
    25# if no occurence, then add it after "use_authtok" 
    26sed -e '/remember=10/!s/use_authtok/& remember=10/' -i /etc/pam.d/system-auth-permanent
    
Thursday, January 15, 2026 Monday, January 1, 1