This is a single entry for the data file I would like to change. 3.2952 CA 3.5579 CA 3.1308 CA 4.9674 CA 4.3178 CA 3.7349 CA 2.7737 CA 3.7845 CA I am trying to figure out how to get all of the numbers next to eachother and remove the "CA" like this: 3.2952 3.5579 3.1308 4.9674 4.3178 3.7349 2.7737 3.7845
#!/usr/bin/perl use strict; my @records; while (<DATA>) { my ($number) = /\s+(\d\.\d+)\s/; push( @records, $number ); } print join ' ', @records; __DATA__ 3.2952 CA 3.5579 CA 3.1308 CA 4.9674 CA 4.3178 CA 3.7349 CA 2.7737 CA 3.7845 CA
3.9708 2.8774 3.7691 3.6411 5.6122 4.3220 3.7427 4.6749 3.8152 2.9114 3.8420 3.7026 5.7437 4.3256 3.7160 4.6640 From this to: 3.9708 2.8774 3.7691 3.6411 5.6122 4.3220 3.7427 4.6749 3.8152 2.9114 3.8420 3.7026 5.7437 4.3256 3.7160 4.6640
my $count; for my $i (0 .. $#records) { print $records[$i] . ' '; $count++; if ( $count == 8 ) { print "\n"; $count = 0; } }
It is printing out like this. The first entry has 8 sets of numbers, but the rest has 7.
$\ = ' '; while (<>) { ($f1) = split ' ' ; print $f1; }