删除冒号之前的所有文本 [英] Remove all text before colon
本文介绍了删除冒号之前的所有文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含一定行数的文件.每行看起来像这样:
I have a file containing a certain number of lines. Each line looks like this:
TF_list_to_test10004/Nus_k0.345_t0.1_e0.1.adj:PKMYT1
我想删除:"字符之前的所有字符,以便仅保留作为基因名称的PKMYT1. 由于我不是正则表达式脚本专家,因此有人可以使用Unix(sed或awk)或R来帮助我做到这一点吗?
I would like to remove all before ":" character in order to retain only PKMYT1 that is a gene name. Since I'm not an expert in regex scripting can anyone help me to do this using Unix (sed or awk) or in R?
推荐答案
以下是在R中执行此操作的两种方法:
Here are two ways of doing it in R:
foo <- "TF_list_to_test10004/Nus_k0.345_t0.1_e0.1.adj:PKMYT1"
# Remove all before and up to ":":
gsub(".*:","",foo)
# Extract everything behind ":":
regmatches(foo,gregexpr("(?<=:).*",foo,perl=TRUE))
这篇关于删除冒号之前的所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文