Command | What It Does |
---|---|
sed –n '/sentimental/p' filex | Prints to the screen all lines containing sentimental. The file filex does not change. Without the –n option, all lines with sentimental will be printed twice. |
sed '1,3d' filex > newfilex | Deletes lines 1, 2, and 3 from filex and saves changes in newfilex. |
sed '/[Dd]aniel/d' filex | Deletes lines containing Daniel or daniel. |
sed –n '15,20p' filex | Prints only lines 15 through 20. |
sed '1,10s/Montana/MT/g' filex | Substitutes Montana with MT globally in lines 1 through 10. |
sed '/March/!d' filex (csh) | Deletes all lines not containing March. (The backslash is used only in the csh to escape the history character.) |
sed '/report/s/5/8/' filex | Changes the first occurrence of 5 to 8 on all lines containing report. |
sed 's/....//' filex | Deletes the first four characters of each line. |
sed 's/...$//' filex | Deletes the last three characters of each line. |
sed '/east/,/west/s/North/South/' filex | For any lines falling in the range from east to west, substitutes North with South. |
sed –n '/Time off/w timefile' filex | Writes all lines containing Time off to the file timefile. |
sed 's/([Oo]ccur)ence/1rence/' file | Substitutes either Occurence or occurence with Occurrence or occurrence. |
sed –n 'l' filex | Prints all lines showing nonprinting characters as nn, where nn is the octal value of the character, and showing tabs as >. |
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8730/viewspace-1034434/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8730/viewspace-1034434/