Farid Ahmadian / Scripts

sed by examples

Example 1


sed -E 's/(\b[0-9]+\b) (\b[0-9]+\b) (\b[0-9]+\b) (\b[0-9]+\b)/\4 \3 \2 \1/g'

Sample Input

    1234 5678 9101 1234  
    2999 5178 9101 2234  
    9999 5628 9201 1232  
    8888 3678 9101 1232

Sample Output

    1234 9101 5678 1234  
    2234 9101 5178 2999  
    1232 9201 5628 9999  
    1232 9101 3678 8888

Example 2


    sed -E 's/([0-9]+ ){3}/**** **** **** /g'

Sample Input

    1234 5678 9101 1234  
    2999 5178 9101 2234  
    9999 5628 9201 1232  
    8888 3678 9101 1232

Sample Output

    **** **** **** 1234
    **** **** **** 2234
    **** **** **** 1232
    **** **** **** 1232

Example 3


    sed -e 's/thy/{&}/Ig'

Input Format

    A text file will be piped to your command via STDIN.

Output Format

    Highlight all occurrences of 'thy'

BY: Farid Ahmadian
TAG: sed
DATE: 2020-06-02 20:36:39


Farid Ahmadian / Scripts [ TXT ]

With many thanks and best wishes for dear Pejman Moghadam, someone who taught me alot in linux and life :)