The file is just like it is.
Indeed there is no space, just continuously no.
The original data has the same start line no. (when I check in notepad),
For example,
the resulting 1st coulomb should started between linecount no 20 to 33 of the original file 1,
and the 2nd col. also linecount 20 to 33 of file 2,
and so on.. it is the same also for all files.
You can just fix that in the awk script. Fix the record and assign the result to $0. That will force recalculation of NF and reassignment to each field variable.
Regards,
Alister
---------- Post updated at 10:39 AM ---------- Previous update was at 09:54 AM ----------
The simplest way to do that is probably:
gsub(/E-/, "E"); gsub(/-/, " -"); gsub(/E/, "E-")
If using gawk, then I suppose gensub with backreferences can manage it in one stroke, like the sed suggestion above.
Thanks for your observation Alister, I had not considered the "E-[0-9][0-9]" part.
The option would be:
awk '{$0=gensub(/([0-9])-/,"\\1 -","g");a[FNR]=a[FNR]?a[FNR] FS $3:$3}END{for (i=1;i in a;i++) print a}' FILE*
or a little bit shorter:
awk '{$0=gensub(/([0-9])-/,"\\1 -","g");a[FNR]=a[FNR]?a[FNR] FS $3:$3}END{for(i in a) print a}' FILE*
my @arr;
my @files = glob("*.txt");
foreach my $f (@files){
open FH,"<$f";
while(<FH>){
my @tmp = split(/(?:(?<=[0-9])(?=-)|\s+)/g,$_);
$arr[$.]= $arr[$.]." ".$tmp[2];
}
close FH;
}
for(my $i=1;$i<=$#arr;$i++){
print $arr[$i],"\n";
}
I just wanted to pointed out a potential unexpected behaviour :
If one of the considered a[FNR] fields of the scanned files has the value 0
the code :
a[FNR]=a[FNR]?a[FNR] FS $3:$3
will behave a wrong way :
a[FNR]? will be evaluated to "false" so that the a[FNR] will be reset to $3 and may lose the previous concatenated values which doesn't fit with what we are looking for ...