Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Confused by the sed command

$
0
0
Hi Gurus,

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

below is command and output.
Code:


sed  '/ddd/{x;p;}' sample.txt
aaa
bbb
ccc
 
      --blank
      --blank
eee
fff
ggg
hhh
iii

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.

Viewing all articles
Browse latest Browse all 16232

Trending Articles