This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Removing Surrounding Pipes Around The Id

I have a tabular file in which the second column which has IDs is surrounded by two pipe characters. I wanna remove these two pipes surrounding the second column of the table Thx

parsing

At the old biostar site, this would have been closed as "off-topic". It is a general programming question, not a bioinformatics question.

And at the new biostar site?

We have the option to close, but not to give a reason. So perhaps we should use the comments to explain why a question is closed. This can be the first test case :)

1 answer

This is so general as to not really be a bioinformatics question. You can open the file in excel (using the text-import wizard), select the column, and do a replace of "|" with nothing. If there are no other columns with pipe characters you can also do a find/replace with any number of text editors (notepad, wordpad, textedit, etc). If the file is too large you can do this with command-line perl as below. Just set $array[num] where "num" is the column you need to scrub (minus 1).

cat test.txt | perl -ne '@array=split("\t", $_); $array[1]=~s/\|//g; print join("\t",@array);'

Log in to answer this question.