Adding a line
Hi
I have a file whose contents are as follows: Code:
sorce1 LEN assumption 695 3570 0.770047 - . ID=f000001.1;source_id=A.off_LEN_10008424; Code:
So for every statement for assumption,I need to add a statement with predictive. So i used this code sed 's/\(.*\)assumption\(.*\)\(ID=[^.]*\)[^;]*\(;.*\)/\1predictive\2\3\4\n&/' file However in my file, I have some instance where there are variants for the id name :For example One variant of id is f000012.1 and the other is f000012.2 this above code worked perfectly well for instance having no variants of IDS. But in case of variants,I am getting a multiple entry of predictive statement for the same ids. result of the code Code:
sorce1 LEN predictive 695 3570 0.770047 - . ID=f000001;source_id=A.off_LEN_10008424; sorce1 LEN predictive 350567 361011 0.628724 + . ID=f000012;source_id=A.off_LEN_10008425; Is there a way I could only add a single line with predictive statement with using the earliest start point i e : and farthest away end point to represent the predictive statement?The ID name shouldnt have variants . thanks in advance |
probably I missed something, your sed is working exactly as you explained, I could not reproduce that problem.
|
A solution in awk, that checks if the ID has been already used:
Code:
/assumption/ { |
now I think I understand: you need only the last line containing the same ID and should be printed at the first occurrence? Is that ok?
that can be solved only in two passes: first you need to parse input file (looking for all the possible IDs) and calculate lines and print the result. |
reply
@ colucix
I used the command : Code:
awk '/assumption/ { |
All times are GMT -5. The time now is 03:34 PM. |