Presentation is loading. Please wait.

Presentation is loading. Please wait.

IT244 - Introduction to Linux / Unix Instructor: Bo Sheng

Similar presentations


Presentation on theme: "IT244 - Introduction to Linux / Unix Instructor: Bo Sheng"— Presentation transcript:

1 IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
The sed Editor(ch 13) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng

2 What is sed Stream editor Syntax 1974, by bell lab Cousin to AWK
sed program [file-list] sed -f program-file [file-list]

3 sed Program Basic syntax Address Instruction Line number
[address[,address]] instruction [argument-list] Address Line number Regular expression Instruction Print (p) Append (a), insert (i), change (c) Write (w) Quit (q)

4 Examples ~it244/it244/scripts/lines sed ‘/line/ p’ lines
By default, sed sends all lines to stdout. sed -n ‘/line/ p’ lines sed -n ‘3,6 p’ lines sed ‘5 q’ lines

5 Examples Append (a) Insert (i) Change (c) ~it244/it244/scripts/append
sed –f append lines Insert (i) ~it244/it244/scripts/insert sed –f insert lines Change (c) ~it244/it244/scripts/change sed –f change lines

6 Examples Substitute (s) ~it244/it244/scripts/subs sed –n –f subs lines
s/search-string/replacement-string/[g][p][w] g:global, p:print, w:write to files ~it244/it244/scripts/subs sed –n –f subs lines ~it244/it244/scripts/sub_write sed –f sub_write lines cat temp

7 Examples Write (w) Next (n) Cleanup sed '2,4 w temp2' lines
~it244/it244/scripts/next sed –n –f next lines Cleanup sed ‘s/ *$//’ file_ex

8 Hold Space Between hold space and pattern space Example
g:copy from HS to PS G:copy from HS to PS and append a newline h:copy from PS to HS H:copy from PS to HS and append a newline x:exchange the contents of PS and HS Example sed ‘G’ lines sed –nf s1 lines


Download ppt "IT244 - Introduction to Linux / Unix Instructor: Bo Sheng"

Similar presentations


Ads by Google