Posts

Showing posts with the label awk

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 print row(s) if they meet a certain range

6 I have two mega files that look like below: f1: chr1,3073253,3074322,gene_id,"ENSMUSG00000102693.1",gene_type,"TEC" chr1,3074253,3075322,gene_id,"ENSMUSG00000102693.1",transcript_id,"ENSMUST00000193812.1" chr1,3077253,3078322,gene_id,"ENSMUSG00000102693.1",transcript_id,"ENSMUST00000193812.1" chr1,3102916,3103025,gene_id,"ENSMUSG00000064842.1",gene_type,"snRNA" chr1,3105016,3106025,gene_id,"ENSMUSG00000064842.1",transcript_id,"ENSMUST00000082908.1" f2: chr,name,start,end chr1,linc1320,3073300,3074300 chr3,linc2245,3077270,3078250 chr1,linc8956,4410501,4406025 What I want to do is to print the rows of file 2 in a separate column in file 1 IF the range of start and ...

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