Hi all,
I have to insert underscore at certain places(places before and after PAxxx/PAxxxx entries in a big file like this
ESR1 PA156 leflunomide PA450192
CHST3 PA26503 docetaxel tungstate Pa4586; thalidomide Pa34958;
PAxxx/PAxxxx entries are metioned between 2 names in each row
I want output shuld be
ESR1_PA156_leflunomide_PA450192_
CHST3_PA26503_docetaxel tungstate_Pa4586_;thalidomide_Pa34958_;
Please let me know scripting regarding this
Try:
perl -pe 's/ +(P(A|a))/_\1/g;s/(P(A|a)\d+) +/\1_/g;s/(P(A|a)\d+); ?/\1_;_/g' file
And how do you get THAT underscore?
Also, you have asked to "insert" an underscore. But, from your output, it seems that you want to replace the white-space (if any) before and after those entries by underscores. Also, the PA entries terminating a line need no underscore at the end?
Please make your requirement very clear and don't leave people guessing. That might be one of the reasons why you need to post your problems in bits and pieces.
Hi all,
I dont want to replace white space with underscore.
I want the place before and after PAxxx/PA xxxx entires with underscore so that I can replace those with a column in excel sheet other wise its not happening because there is some time white space between 2 words between PA entries and I do not want to separate those in a column. Therefore,I do not want underscore there and I wan underscore only before and after PAxxx/PAxxxx entries.
I tried the above mentioned programm but it shows following error:
-bash-3.2$ perl -pe 's/ +(P(A|a))/_\1/g;s/(P(A|a)\d+) +^1_/g;s/(P(A|a)\d+); ?^1_;_/g' T2Dnew2 >T2Dnew3
Backslash found where operator expected at -e line 1, near ")\"
(Missing operator before \?)
syntax error at -e line 1, near "s/(P(A|a)\d+) +^1_/g;s/("
Search pattern not terminated or ternary operator parsed as search pattern at -e
But the expected output is
ESR1_PA156_leflunomide_PA450192_
CHST3_PA26503_docetaxel tungstate_Pa4586_;thalidomide_Pa34958_;
This is not the code I posted:
perl -pe 's/ +(P(A|a))/_\1/g;s/(P(A|a)\d+) +^1_/g;s/(P(A|a)\d+); ?^1_;_/g'
This is:
perl -pe 's/ +(P(A|a))/_\1/g;s/(P(A|a)\d+) +/\1_/g;s/(P(A|a)\d+); ?/\1_;_/g'