Sed - An Introduction and Tutorial by Bruce Barnett
|
It isn't obvious,but?sed?could be used instead of?tr. You can embed a new line in a substitute command,but you must escape it with a backslash. It is unfortunate that you must use "n" in the left side of a substitute command,and an embedded new line in the right hand side. Heavy sigh. Here is the example: #!/bin/sh
sed '
s/ /
/' |
sed ' {
y/abcdef/ABCDEF/
N
s/n/ /
}'
Click here to get file:? Sometimes I add a special character as a marker,and look for that character in the input stream. When found,it indicates the place a blank used to be. A backslash is a good character,except it must be escaped with a backslash,and makes the?sed?script obscure. Save it for that guy who keeps asking dumb questions. The?sedscript to change a blank into a "" following by a new line would be:?#!/bin/shsed 's/ //' file Click here to get file:? Yeah. That's the ticket. Or use the C shell and really confuse him!?#!/bin/csh -fsed 's/ /\/' file Click here to get file:? A few more examples of that,and he'll never ask you a question again! I think I'm getting carried away. I'll summarize with a chart that covers the features we've talked about:
相关内容
站长推荐
|

