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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

edit text file

Status
Not open for further replies.

noyk

MIS
Feb 20, 2009
23
0
0
MY
How do i change this

YAL044W-A 0000004, 0005554, 0008372

to this?

YAL044W-A 0000004
YAL044W-A 0005554
YAL044W-A 0008372

it doesnt have to be programmatic if there is a way doing it using 'replace with' function in any text editor

Thanks a lot
 
read in your line
split it
write out the requisite lines

Code:
open FH, "<infile.txt" or die $!;
open OF, ">outputfile.txt";
while (<FH>) {
  ($key, @values)=split /\s+/, $_;
  foreach (@values) {
    print OF, "$key\t$_";
  }
}
You may wish to get rid of the commas, but I'll leave that up to you ...

NOT TESTED
}

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
can you explain these lines

<code>
while (<FH>) {
($key, @values)=split /\s+/, $_;
foreach (@values) {
print OF, "$key\t$_";
}
</code>
 
Code:
while (<FH>) {       # read the file, line by line into $_
  ($key, @values)=split /\s+/, $_; set $key to the first item in the line, and the rest of the values gathered by the split get dumped into the array
  foreach (@values) { # traverse the array, and output the key value, and each item in the array on a seperate line
    print OF, "$key\t$_";
  }
}

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top