Posts

Showing posts with the label sed

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 ...

How to add an integer to a difference calculation and print it to the end of a line?

6 Goal: To print the difference between two fields separated by semicolons ( $3 and $2 ) and add an integer ( +1 ) to that calculated value at the end of each line beginning with " > ". Representative sample of my file: >lcl|ORF1_ 17609 17804 (+):21:131 unnamed protein product MEKVKNKFDENDIKVPFVPSSLLFNNTGNLNTMDKR >lcl|ORF2_ 17609 17804 (+):70:111 unnamed protein product MFLLHYYLIIQVI >lcl|ORF3_ 17609 17804 (+):112:147 unnamed protein product MQWIKDKVLIK >lcl|ORF4_ 17609 17804 (+):129:91 unnamed protein product MFYPLYLDYLYY >lcl|ORF5_ 17609 17804 (+):90:1 unnamed protein product, partial MIMKKEQMELLYHSHQIYFLPFPLHQNIHP Desired Output: >lcl|ORF1_ 17609 17804 (+):21:131 unnamed protei...