adding line
Query related to adding a particular line in my file.
My original file looks like this sorce1 LEN assumption 695 3570 0.770047 - . ID=f000001.1;source_id=A.off_LEN_10008424; sorce1 LEN descriptive 3334 3570 . - 0 Parent=f000001.1; sorce1 LEN extra 913 993 . - 0 Parent=f000001.1; sorce1 LEN descriptive 695 736 . - 0 Parent=f000001.1; sorce1 LEN assumption 8859 11328 0.628724 + . ID=f000002.1;source_id=A.off_LEN_10008425; sorce1 LEN descrptive 8859 9032 . + 0 Parent=f000002.1; sorce1 LEN assumption 24331 34483 1 - . ID=f000003.1;source_id=A.off_LEN_10008426;part_support_id=CUFF1.1.1; sorce1 LEN extra 34479 34483 . - 0 Parent=f000003.1; For every line which has assumption in 3rd column, I have to add a line which has an entry"predictive " in 3rd column. It can be seen in bolded line The added line needs to have the 3rd column entry as predictive. An example: result file should look like this sorce1 LEN predictive 695 3570 0.770047 - . ID=f000001;source_id=A.off_LEN_10008424; sorce1 LEN assumption 695 3570 0.770047 - . ID=f000001.1;source_id=A.off_LEN_10008424; sorce1 LEN descriptive 3334 3570 . - 0 Parent=f000001.1; sorce1 LEN extra 913 993 . - 0 Parent=f000001.1; sorce1 LEN descriptive 695 736 . - 0 Parent=f000001.1; sorce1 LEN predictive 8859 11328 0.628724 + . ID=f000002;source_id=A.off_LEN_10008425; sorce1 LEN assumption 8859 11328 0.628724 + . ID=f000002.1;source_id=A.off_LEN_10008425; sorce1 LEN descrptive 8859 9032 . + 0 Parent=f000002.1; [B]sorce1 LEN predictive 24331 34483 1 - . ID=f000003;source_id=A.off_LEN_10008426;part_support_id=CUFF1.1.1; sorce1 LEN assumption 24331 34483 1 - . ID=f000003.1;source_id=A.off_LEN_10008426;part_support_id=CUFF1.1.1; sorce1 LEN extra 34479 34483 . - 0 Parent=f000003.1; Please do help on what I could do to add a line for every statement which has assumption in 3rd column Thanks |
With this InFile ...
Code:
Code:
awk '{save=$0; Code:
|
Looking at the data provided I wonder if specifically looking at column 3 is needed.
Here's a sed solution based on that: Code:
sed -r '/assumption/{ h ; s/assumption/predictive/ ; G }' infile Code:
$ sed '/assumption/{ h ; s/assumption/predictive/ ; G }' infile |
Thanks for your valuable suggestion.
This definitely changes the 3rd columns but is there a way I could modify the id values as well sorce1 LEN predictive 695 3570 0.770047 - . ID=f000001;source_id=A.off_LEN_10008424; sorce1 LEN assumption 695 3570 0.770047 - . ID=f000001.1;source_id=A.off_LEN_10008424; sorce1 LEN descriptive 3334 3570 . - 0 Parent=f000001.1; sorce1 LEN extra 913 993 . - 0 Parent=f000001.1; sorce1 LEN descriptive 695 736 . - 0 Parent=f000001.1; sorce1 LEN predictive 8859 11328 0.628724 + . ID=f000002;source_id=A.off_LEN_10008425; sorce1 LEN assumption 8859 11328 0.628724 + . ID=f000002.1;source_id=A.off_LEN_10008425; |
@sam@: Try this:
Code:
sed -r '/assumption/{ h ; s/assumption/predictive/ ; s/ID=(.*[0-9])\.[0-9];s/ID=\1;s/; G }' infile Code:
$ sed -r '/assumption/{ h ; s/assumption/predictive/ ; s/ID=(.*[0-9])\.[0-9];s/ID=\1;s/; G }' infile |
Quote:
Code:
sorce1 LEN assumption 695 3570 0.770047 - . ID=f000001.1;abc Code:
awk '{save=$0; Code:
sorce1 LEN predictive 695 3570 0.770047 - . ID=f000001;abc Daniel B. Martin |
All times are GMT -5. The time now is 04:29 PM. |