sed 's/day/night/' |
s Substitute command
/../../ Delimiter
day Regular Expression Pattern Search Pattern
night Replacement string
Using & as the matched string
% echo "123 abc" | sed 's/[0-9]*/& &/' 123 123 abc |
Using \1 to keep part of the pattern
sed 's/\([a-z]*\) \([a-z]*\)/\2 \1/' |
/g – Global replacement
sed 's/[^ ][^ ]*/(&)/g' <old >new |
Multiple commands with -e command
sed -e 's/a/A/' -e 's/b/B/' <old >new |
Passing arguments into a sed script
#!/bin/sh sed -n 's/'"$1"'/&/p' |
notice :
{} () has to be escaped as \{\} \(\)
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.