0

I have a file containing multiple rows of the following format

[Site "https://sitename.com/8994DX1"]
[Date "1999.11.04"]
...
[Site "https://sitename.com/678489s"]
[Date "2000.12.04"]
...
[Site "https://sitename.com/788Xxz"]
[Date "2020.12.04"]

I want to prepend the original site line with a semi-colon. I want to add a new dummy site line, which has the same sitename every time.

;[Site "https://sitename.com/8994DX1"]
[Site "https://sitename.com/12345"]
[Date "1999.11.04"]
...
;[Site "https://sitename.com/678489s"]
[Site "https://sitename.com/12345"]
[Date "2000.12.04"]
...
;[Site "https://sitename.com/788Xxz"]
[Site "https://sitename.com/12345"]
[Date "2020.12.04"]

In other words, I want to make the original unique sitename a comment, and in a new unvarying sitename.

I found this question which is close, but I haven't managed to modify it to do what I need.

Thanks for any suggestions.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
user3185563
  • 1,314
  • 2
  • 15
  • 22
  • 1
    pointing us to a different question doesn't tell us what you've tried nor does it give us any idea what modifications you've attempted; please update the question with the actual `sed` code you've tried along with the (wrong) result generated by said code – markp-fuso Oct 15 '22 at 21:21
  • I assume your desired output is wrong. – Cyrus Oct 15 '22 at 21:24

1 Answers1

0

This sed command should do the trick:

sed -i.bak '
/^\[Site /!b
s/^/;/
a\
[Site "https://sitename.com/12345"]
' file
M. Nejat Aydin
  • 9,597
  • 1
  • 7
  • 17