2

I am doing:

egrep -e "String" -in -A 2 file1.log

I am getting output as

111:some text
112-some text
113-some text

How to replace ^'[0-9]{1,9}-' to ^'[0-9]{1,9}:' for each line number at start of each line in a file? So that it will look like:

111:some text
112:some text
113:some text
Thor
  • 45,082
  • 11
  • 119
  • 130
ypp
  • 141
  • 10
  • Take a look at http://stackoverflow.com/questions/1169927/using-sed-and-grep-to-search-and-replace, hope it helps! – Mattias Lindberg Sep 24 '15 at 10:37
  • I tried but not worked. I am looking solution like this egrep -e "String" -in -A 2 file1.log | sed 's/^'[0-9]{1,9}-'/^'[0-9]{1,9}:'/' – ypp Sep 24 '15 at 10:57

1 Answers1

1

Pipe the output into sed. This works here:

grep ... | sed 's/^\([0-9]\+\)-/\1:/'
Thor
  • 45,082
  • 11
  • 119
  • 130
  • Thanks a lot thor :) , yes its working but it also deleting group separators '--'. Just as workaround I changed group separators as '==' using this option of grep "--group-separator==" – ypp Sep 24 '15 at 11:48
  • @ypp: Yes I noticed that and changed the pattern to use the `\+` quantifier instead of `*`. – Thor Sep 24 '15 at 12:30