I'm running Fedora 30 and want to write a bash script. I have a file with test data
asdf
asdf
[test]
asdasd
[test]
asdasd
i want to insert "lineToInsert" before the second occurrence of [test]
So far i have
myVar="lineToInsert"
sed '/\[test\]/i'$myVar inputTest > test.txt
The problem is that this insert "lineToInsert" before every occourrence of [test]. Resulting in
asdf
asdf
lineToInsert
[test]
asdasd
lineToInsert
[test]
asdasd
What i want is this
asdf
asdf
[test]
asdasd
lineToInsert
[test]
asdasd