Skip to main content
1 of 2
sjngm
  • 547
  • 1
  • 6
  • 15

Insert Line in File When Group of Lines Changes

Let's say I have a text file like this:

group1 hello group1 there group1 nice line group2 here group2 we group2 go 

What I want to do is insert a line when the group of lines changes, something like:

group1 hello group1 there group1 nice line --------------------------------------- group2 here group2 we group2 go 

I don't care if that line also appears as the first and/or last line. At this time I only need something that separates the information.

How do I do that with sed/awk? Or maybe there are other ways?

sjngm
  • 547
  • 1
  • 6
  • 15