Hi Gurus,
I am a little bit confused by the sed command.
my file is below
below is command and output.
as per my understanding, {x;p;} when match found, x -- exchange hold place with pattern place which is null with ddd, then p; print, I thought it only print once, but here it prints twice.
Please help me to understand this, thanks in advance.
Ps, I think I figured out this. it works as below. x -- exchange hold place with pattern place which is empty. with ddd then p; print. after finish these two. the default is "print pattern space", so it prints the pattern space content again which is empty.
Please correct me if anything incorrect.
I am a little bit confused by the sed command.
my file is below
Code:
cat sample
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
Code:
sed '/ddd/{x;p;}' sample.txt
aaa
bbb
ccc
--blank
--blank
eee
fff
ggg
hhh
iii
Please help me to understand this, thanks in advance.
Ps, I think I figured out this. it works as below. x -- exchange hold place with pattern place which is empty. with ddd then p; print. after finish these two. the default is "print pattern space", so it prints the pattern space content again which is empty.
Please correct me if anything incorrect.