Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extracting data and merge

Status
Not open for further replies.

amili

Programmer
Nov 9, 2010
18
CA
hi,

i have a file that contains ID, Name, Start, End, Circular and Function. I just need ID and Name. i use below script and it works.

#!/usr/bin/perl
open (MYFILE, '>scaffold_1.txt');
select (MYFILE);
open (FILE, 'scaffold_11.txt');

while (<FILE>)
{
chomp;
my @fields = split /\|/;
my @output = grep /^(ID|NAME)/, @fields;
print join("\t", @output), "\n";
}

close (FILE);
exit;

but it gives me output with lots of blank spaces. How can i get output like below?


ID PHCHR1_10
NAME PHCHR1_10
ID PHCHR1_100
NAME PHCHR1_100
ID PHCHR1_1000
NAME PHCHR1_1000

also, how to get output with tab within it like below?

PHCHR1_10 PHCHR1_100 PHCHR1_1000

thanks..
 
It sounds like you have spaces between your delimiter. Try changing your split() function to include white-space like this:

my @fields = split /\s*\|\s*/;
 
hi,

thanks for your prompt response.
i tried but it does not give me anything. all the data gone.

thanks..
 
sorry, was a mistake...i missed some part..however..it does not give any difference to my output that i posted. thanks
 
It's difficult for anyone to answer without seeing what you're working with. Please post some sample data that have been scrubbed of any sensitive information.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top