Insert a line after pattern match, if only the string does not exists

5

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: `-'
Share
Improve this question
1
  • 6
    @WiktorStribiżew : That will substitute line -- rover-heal with cpu-management.. Im looking to add it in next line – voltas Apr 9 at 12:34

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue