Reputation: 21
sed -i -e 's_.*_text-to-be-insterted-on-each-line&_' '/media/root/<filename>'
works well and is concise and clean like i prefer.....but i dont / cant find ANY information about the ninja commands used - not in manual nor google.
but im having trouble understanding from example how _.*_
is translated
and how &_ is being used exactly &_
is being used
if someone could explain GREAT or any resources that document these unique sed commands?
Upvotes: 2
Views: 810
Reputation: 195269
s_.*_foo&_
is same as:
s/.*/foo&/
You can use other separators as well, for example:
s#.*#foo&# or s@patter@replacement@
Some time it is convenient to use separator other than /
in s
substitution. For example, you want to do some changes on file path.
The &
in replacement part, means the matched group 0 with the given pattern (regex).
An example may better explain:
kent$ sed 's/aa/*&*/'<<<'aabbcc'
*aa*bbcc
You have seen that the matched group 0 is aa
in above input string.
Upvotes: 2