Changes between Version 2 and Version 3 of Csle2022/Agenda/linuxfilters


Ignore:
Timestamp:
Nov 29, 2022, 12:28:29 AM (2 years ago)
Author:
deepthi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Csle2022/Agenda/linuxfilters

    v2 v3  
    1001001.Replacing or substituting string : Sed command is mostly used to replace the text in a file. The below simple sed command replaces the word “unix” with “linux” in the file.
    101101
    102 `$sed 's/unix/linux/' geekfile.txt`
     102`$sed 's/unix/linux/' test.txt`
    103103
    1041042. Replacing the nth occurrence of a pattern in a line : Use the /1, /2 etc flags to replace the first, second occurrence of a pattern in a line. The below command replaces the second occurrence of the word “unix” with “linux” in a line.
    105105
    106 `$sed 's/unix/linux/2' geekfile.txt`
     106`$sed 's/unix/linux/2' test.txt`
    107107
    1081083.Replacing all the occurrence of the pattern in a line : The substitute flag /g (global replacement) specifies the sed command to replace all the occurrences of the string in the line.
    109109
    110 `$sed 's/unix/linux/g' geekfile.txt`
     110`$sed 's/unix/linux/g' test.txt`
    111111
    1121124.Replacing from nth occurrence to all occurrences in a line : Use the combination of /1, /2 etc and /g to replace all the patterns from the nth occurrence of a pattern in a line. The following sed command replaces the third, fourth, fifth… “unix” word with “linux” word in a line.
    113113
    114 `$sed 's/unix/linux/3g' geekfile.txt`
     114`$sed 's/unix/linux/3g' test.txt`
    115115
    1161165.Parenthesize first character of each word : This sed example prints the first character of every word in parenthesis.
    117117
    118 `$ echo "Welcome To The Geek Stuff" | sed 's/\(\b[A-Z]\)/\(\1\)/g'`
     118`$ echo "Welcome To The Test Stuff" | sed 's/\(\b[A-Z]\)/\(\1\)/g'`
    119119
    1201206.Replacing string on a specific line number : You can restrict the sed command to replace the string on a specific line number. An example is
    121121
    122 `$sed '3 s/unix/linux/' geekfile.txt`
     122`$sed '3 s/unix/linux/' tezt.txt`
    123123
    1241247.Duplicating the replaced line with /p flag : The /p print flag prints the replaced line twice on the terminal. If a line does not have the search pattern and is not replaced, then the /p prints that line only once.
    125125
    126 `$sed 's/unix/linux/p' geekfile.txt`
     126`$sed 's/unix/linux/p' test.txt`
    127127
    1281288.Printing only the replaced lines : Use the -n option along with the /p print flag to display only the replaced lines. Here the -n option suppresses the duplicate rows generated by the /p flag and prints the replaced lines only one time.
    129129
    130 `$sed -n 's/unix/linux/p' geekfile.txt`
     130`$sed -n 's/unix/linux/p' test.txt`
    131131
    1321329.Replacing string on a range of lines : You can specify a range of line numbers to the sed command for replacing a string.
    133133
    134 `$sed '1,3 s/unix/linux/' geekfile.txt`
     134`$sed '1,3 s/unix/linux/' test.txt`
    135135
    13613610.Deleting lines from a particular file : SED command can also be used for deleting lines from a particular file. SED command is used for performing deletion operation without even opening the file
     
    199199
    200200
    201 
    202 
    203 
    204 
    205 
    206 
    207 
    208