Insert a line after pattern match, if only the string does not exists
5
1
Input file Ranges: - PeakK2:8.8.9 - rover-heal:3.3.1 Arg: V1 change: 1 Firstly, check if the string cpu-management exists in the file, if not add it after the rover-heal line like below. Ranges: - PeakK2:8.8.9 - rover-heal:3.3.1 - cpu-management:1.9.0 Arg: V1 change: 1 I came up with a one liner grep -e "cpu-management:" test.yaml || sed -i -e "/rover-heal/- cpu-management:${version}/" test.yaml where version is the environmental variable. Error: sed: -e expression #1, char 16: unknown command: `-'
awk sed grep
Share
...