Reputation: 13
I need to split a long non-delimited series of numbers using awk. How would I split this:
91.5799.3677.48107.5981.26
using awk to produce this:
91.57
99.36
77.48
107.59
81.26
Upvotes: 1
Views: 123
Reputation: 41456
Here is an awk
as requested..
awk 'NR==1 {s=$1} NR>1 {e=substr($1,1,2);print s "." e;s=substr($1,3)}' RS="." <<< "91.5799.3677.48107.5981.26"
91.57
99.36
77.48
107.59
81.26
Another version
awk '{for (i=1;i<=NF;i++) {if ($i==".") f=i;printf "%s"(f&&i==f+2?RS:""),$i}}' FS=""
91.57
99.36
77.48
107.59
81.26
Upvotes: 1
Reputation: 28000
If GNU grep is not available and Perl is acceptable:
perl -pe's|\...(?!\Z)|$&\n|g' infile
GNU awk:
awk 'NF&&$0=$0RT' RS='\\...' infile
Upvotes: 1
Reputation: 785146
It might be easier with egrep
:
s='91.5799.3677.48107.5981.26'
egrep -o '[^.]*.[0-9]{2}' <<< "$s"
91.57
99.36
77.48
107.59
81.26
Upvotes: 5