首页 > 科技 > sed

sed

2006年2月10日 16点52分 发表评论 阅读评论

Sed is a stream editor which modify the copy of original file.Of course we could re-direct the output file to a named result.
Sed syntax: # sed sed_command input_file
the following option are ofen used with sed:
-n : suppress automatic printing and pattern space

There are two ways to query text by using sed: line number and Regular expressions.
print syntax: [address[,address] p
eg: print the 2nd line
# sed -n ‘2p’ test.txt
print the 2nd and 3rd lines
# sed -n ‘2,3p’ test.txt
print the line which match the identified strings:
# sed -n ‘/Yellow/’p test.txt
or # sed -n ‘/Yellow/p’ test.txt
Using mode and line number to query:
line_number,/pattern/ (, is comma)
# sed -n ‘4,/The/’p test.txt
print the last line:
# sed -n ‘$’p test.txt
delete line by using “d”
# sed ‘1d’ test.txt
write the output file created by sed to a new file:
# sed ‘1,2 w new_file’ test.txt

How to know if there are controlling characters in the text? if issue the “# cat -v filename”, the system beeps and there are many stranger characters displaying in the screen, it means the text file has controlling characters.

分类: 科技 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.