Issue
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.
Solution
This sed
command should do the trick:
sed -i.bak '
/^\[Site /!b
s/^/;/
a\
[Site "https://sitename.com/12345"]
' file
Answered By - M. Nejat Aydin Answer Checked By - Pedro (WPSolving Volunteer)