ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
The initial information in the file is in order, is correct, I only add the name ">gi|...|" and change the "orf###" order, not for any line, each line ">gi|...|" have a lot of "orf###", first are the ">gi|...|" and then its "orf###".
Originally Posted by grail
Your information seems a little bit unusual? Are you saying that the original data is in the incorrect order? As you have changed the orf* values but left the rest of the data from
Well if perl is not your strength, what else can you use? I am more familiar with ruby or awk, but the idea is for you to make some attempt as so far you have only copied someone else.
Do you understand the snippet you copied?
This is the break down, might help you out:
$p=$1 if /^>gi\|(.*)\|/ - So to a beginner this may seem a little backward, but the if is evaluated first and when true $p (scalar variable) gets assigned what is in $1 (hmmm back reference I think).
So the "if" says, when the start of the line (^) is followed by the string ">gi\|" (the slosh (\) before the pipe (|) is so it is a literal pipe and not misunderstood), then save everything ((.*))
up until the last pipe (\|) [the save is put into $1]. When all that is true do the assignment.
print $p." ".$_ if /^orf/ - Again if is first. "if" the line starts (^) with the string "orf", then print the previously stored variable $p concatenated (.) with a space and concatenated with the current
Right ... well good to see you have a solution but most of the Perl gurus will be rolling over in their graves I know you are new to Perl, but it can in fact do all the tasks that cut
and sed have done for you and also have a plethora of formatting abilities.
Oh, and the comment about awk is also incorrect, again you just need to learn a bit more about it
In case you are interested, here are some helpful links: